llo,我正在尝试将我的 webapp 与 php 中的 RESTful api 集成。这需要我将数据发布到https://api.api.ai/v1/query并且还有 2 个自定义标头。
我目前的代码是
$data = array("v" => "20150821", "query" => "whats the time", "lang" => "EN", "sessionId" => "1234567890");
$data_string = json_encode($data);
$ch = curl_init('https://api.api.ai/v1/query');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
// 'Content-Length: ' . strlen($data_string),
'Content-type: application/json',
'Authorization: Bearer XxxX-xxx',
'ocp-apim-subscription-key: XxxX-xxx')
);
$result = curl_exec($ch);
如果我运行它,(使用我的真实身份验证和密钥 obv)我什么也得不到。就像空白一样。有任何想法吗?