use GuzzleHttp\Client;
$client = new Client();
$response = $client->request('GET', 'http://xx.com');
$code = $response->getStatusCode();//獲取http響應狀態碼
$data = $response->getBody()->getContents();//獲取響應內容
//--GET請求添加參數
$params = [
'headers' => [//請求頭信息
'token' => 'VBkmpUn8BPMPPNXJnP8CvneYBpQFDdfnetnxQT3C...'
],
'query' => [//附加參數
'type' => 1
]
];
$response = $client->request('GET','http://xx.com',$params);
//--POST請求添加參數
$params = [
'headers' => [//請求頭信息
'token' => 'VBkmpUn8BPMPPNXJnP8CvneYBpQFDdfnetnxQT3C...'
],
'form_params' => [//附加參數
'first_name' => '週末啦',
'last_name' => 'lalala',
'email' => '[email protected]',
'desc' => '週末啦週末啦週末啦週末啦',
],
'json' => [//傳數組
['name'=>'zs','age'=>10],
['name'=>'zs','age'=>10],
['name'=>'zs','age'=>10],
]
];
$response = $client->request('POST','http://loc.nva.com/app/message',$params);
鏈接:https://www.cnblogs.com/mg007/p/11202775.html
使用過程中報cURL error 60: SSL certificate problem: unable to get local issuer certificate錯誤
1.下載 cacert.pem文件
2.放在/php-7.2.1-nts/extras/ssl 文件下【本地PhpStudy環境】
3.修改php.ini文件:curl.cainfo = "F:/MyProgram/PHPTutorial/php/php-7.2.1-nts/extras/ssl/cacert.pem"
問題解決!