似乎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();
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
根据http://docs.guzzlephp.org/en/latest/request-options.html,您应该将标头编写为关联数组。
所以,尝试
$client = new Client(['headers' => ['Accept' => 'application/json']]);
Run Code Online (Sandbox Code Playgroud)