Guzzle - 如何设置json Header?
Guzzle - How to set json Header?
似乎 Accept: application/json
还没有为请求 header 设置。我没有收到 json 回复。
$params = [
'client_id' => 'xxxx',
'client_secret' => 'xxxxxxxxxx',
'code' => $request->get('code'),
'state' => $request->get('state'),
];
$client = new Client(['headers' => ['Accept: application/json']]);
$response = $client->post($tokenUrl, [
'form_params' => $params,
]);
echo $response->getBody();
我该如何解决这个问题?
根据http://docs.guzzlephp.org/en/latest/request-options.html,你应该将headers写成关联数组。
所以,试试
$client = new Client(['headers' => ['Accept' => 'application/json']]);
似乎 Accept: application/json
还没有为请求 header 设置。我没有收到 json 回复。
$params = [
'client_id' => 'xxxx',
'client_secret' => 'xxxxxxxxxx',
'code' => $request->get('code'),
'state' => $request->get('state'),
];
$client = new Client(['headers' => ['Accept: application/json']]);
$response = $client->post($tokenUrl, [
'form_params' => $params,
]);
echo $response->getBody();
我该如何解决这个问题?
根据http://docs.guzzlephp.org/en/latest/request-options.html,你应该将headers写成关联数组。
所以,试试
$client = new Client(['headers' => ['Accept' => 'application/json']]);