我通过guzzle向api.ai发送GET请求,但得到了回复:
{ "id": "83a493c7-386f-4e0a-93f8-6e3647f0f1be", "timestamp": "2017-07-29T19:40:22.172Z", "lang": "en", "status": { "code": 400, "errorType": "bad_request", "errorDetails": "Required 'lang' parameter is empty." } }
以下是我的代码:
try {
$res = $client->request('GET', 'https://api.api.ai/v1/query?
query=weather&lang=\"en\"');
}
catch (\GuzzleHttp\Exception\ClientException $e) {
$response = $e->getResponse();
$responseBodyAsString = $response->getBody()->getContents();
echo $responseBodyAsString;
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
fwrite($myfile, \GuzzleHttp\json_encode($e->getResponse('Status'),true));
fclose($myfile); die();
}
答案 0 :(得分:0)
这是网址编码错误。我通过删除“放大器”解决了它来自网址。