【发布时间】:2017-03-01 19:30:29
【问题描述】:
我知道有一个由个人 (https://github.com/tgallice/wit-php) 创建的库。但是,我找不到他是如何格式化卷曲的。我只想做一个请求,所以使用他的库会是大材小用。
这是在终端中工作的字符串,但我不确定如何用 PHP 编写:curl -H 'Authorization: Bearer ACCESSCODE' 'https://api.wit.ai/message?v=20160526&q=mycarisbroken'
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL,"https://api.wit.ai/message?v=20160526&q=my%20car%20doesnt%20work");
curl_setopt($ch1, CURLOPT_POST, 1);
// curl_setopt($ch1, CURLOPT_POSTFIELDS,$vars); //Post Fields
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
$headers = [
'Authorization: Bearer ACCESSCODEOMITTED',
];
curl_setopt($ch1, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch1, CURLOPT_HEADER, true);
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, false);
$server_output = curl_exec ($ch1);
curl_close($ch1);
Data::$answer = json_decode($server_output)['entities']['intent'][0]['value'];
【问题讨论】:
-
签出libcurl
-
@HassanAhmed 我不知道 -H 是什么,所以这个链接没有多大帮助
-
curl 中的 -H 标志代表您发送到服务器的标头
-
@HassanAhmed 我仍然无法正确处理,不确定这是 GET 还是 POST。标题会卷曲到哪里?
-
默认 curl 命令请求类型是 GET ,只要你没有定义为 POST