PHP code example of itboye / component_http

1. Go to this page and download the library: Download itboye/component_http library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

itboye / component_http example snippets



use by\component\http\HttpRequest;

$http = new HttpRequest;
$response = $http->ua('ByHttp')
                 ->get('http://www.baidu.com');

echo 'html:', PHP_EOL, $response->body();


use by\component\http\ByHttp\Http\Request;
use by\component\http\ByHttp;

$url = 'http://www.baidu.com';

// 构造方法定义:__construct($uri = null, array $headers = [], $body = '', $method = RequestMethod::GET, $version = '1.1', array $server = [], array $cookies = [], array $files = [])
$request = new Request($url);

// 发送请求并获取结果
$response = ByHttp::send($request);

var_dump($response);