PHP Curl Http Client
Http Client Support Http Method : GET, POST, PUT , DELETE
protected $client ;
function __construct()
{
$this->client = HttpClientBuilder::create()->build();
}
$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);
$data = [
'uri'=>'https://www.baidu.com',
'params'=> [
'user'=>ethan
]
];
return $this->client
->setHeaders('Content-Type:application/json')
->Post($data);
$data = [
'uri'=>'https://www.baidu.com',
'params'=> [
'user'=>ethan
]
];
return $this->client
->setHeaders('Content-Type:application/json')
->Put($data); // Delete($data)
文件上传