Skip to content

Latest commit

 

History

History
71 lines (49 loc) · 1.04 KB

README.md

File metadata and controls

71 lines (49 loc) · 1.04 KB

PHP Curl Http Client

Usage

Http Client Support Http Method : GET, POST, PUT , DELETE

构建 HttpClient

protected $client ;
function __construct()
{
    $this->client = HttpClientBuilder::create()->build();
}

GET Request

$data = [
    'uri'=>'https://www.baidu.com'
];

return $this->client
    ->setHeaders('Content-Type:application/json')
    ->setHeaders('X-HTTP-Method-Override:GET')
    ->setHeaders('Request_id: Ethan')
    ->setTimeout(10)
    ->Get($data);

POST Request

$data = [
    'uri'=>'https://www.baidu.com',
    'params'=> [
        'user'=>ethan
     ]
];

return $this->client
    ->setHeaders('Content-Type:application/json')
    ->Post($data);

PUT 、DELETE Request

$data = [
    'uri'=>'https://www.baidu.com',
    'params'=> [
        'user'=>ethan
     ]
];

return $this->client
    ->setHeaders('Content-Type:application/json')
    ->Put($data); // Delete($data)

扩展

文件上传