composer require guzzlehttp/guzzle
use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar;
$cookieJar = CookieJar::fromArray([
'token' => '221FB9D3-968E'
], 'api.aaaa.com'); // 此处记得请求域名需要保持跟请求的url host一致,否则不会携带此cookie。
$client = new Client([
'cookies' => $cookieJar,
'headers'=>[
'User-Agent' => 'okhttp/3.8.1',
'Host' => 'api.aa.com',
'Connection' => 'Keep-Alive',
'Accept-Encoding' => 'gzip',
"Access-Token" => '104231665f5749ecd79122edbcb89b55f7c55e40',
"Content-type" => 'application/json',
"Referer" => 'https://wx.aa.com/dweb2/index/group/',
"Origin" => 'https://wx.aa.com',
]
]);
$result = $client->get($url);
$ret_json = $result->getBody()->getContents();
$ret_arr = json_decode($ret_json, true);
$result = $client->post($url, [
'form_params' => [
'name'=>'aaa'
]
]);
$result = $client->post($url, [
'json' => [ //参数组
'req_data'=> [
'name'=>'aaa'
]
],
]
);
$result = $client->post($url, [
'json' => [ //参数组
'req_data'=> [
'name'=>'aaa'
]
],
'multipart' => [
[
'name' => 'file',
'contents' => fopen($upload_file, 'r')
],
]
]
);
$response = $client->get('http://httpbin.org/get');
$response = $client->delete('http://httpbin.org/delete');
$response = $client->head('http://httpbin.org/get');
$response = $client->options('http://httpbin.org/get');
$response = $client->patch('http://httpbin.org/patch');
$response = $client->post('http://httpbin.org/post');
$response = $client->put('http://httpbin.org/put');
参考:https://blog.csdn.net/qq_44077052/article/details/125988456