llo,我正在尝试将我的webapp与RESTful api集成到php中。这要求我将数据发布到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);如果我运行这个,(用我真正的注意事项),我什么也得不到。比如布兰克。有什么想法吗?
发布于 2015-08-21 11:10:39
我非常地抱歉。我睡得不好,犯了一个相当愚蠢的错误,我忘了回$result
我知道,我知道。无论如何,我得更加小心一点,谢谢。
https://stackoverflow.com/questions/32138423
复制相似问题