似乎尚未为请求标头设置Accept: application/json
。我没有得到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();
我该如何解决这个问题?
答案 0 :(得分:3)
根据http://docs.guzzlephp.org/en/latest/request-options.html,您应该将标题写为关联数组。
所以,试试
$client = new Client(['headers' => ['Accept' => 'application/json']]);