php - 使用 php CURL 将文档添加到 IBM Watson Discovery
问题描述
我一直在尝试使用使用 PHP CURL 的 Watson Discovery API 将文档添加到集合中,但没有成功。这是我到目前为止所得到的:
$doc = 'documents/comment_' . $id . '.json';
$fields = [
'file' => new \CURLFile($doc, 'application/json', 'comment_' . $id)
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . $method);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_USERPWD, 'apikey:' . $apikey);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
我意识到这可能不正确,但我尝试了各种组合,但没有得到任何结果——即没有错误消息,什么也没有。任何人都可以建议我可能会出错的地方吗?
PHP 7.0 (Laravel)
解决方案
尝试类似的方法,至少获得一些“为什么”的信息:
$response = curl_exec($ch);
if($response == false){
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
}
$curl_info = curl_getinfo($ch);
此外,在那里安装xDebug可能会有很大帮助。
推荐阅读
- android - 在嵌套场景中传递道具反应原生路由器通量
- android - 如何修复 BluetoothGATT 中的 onClientConnectionState() - status=22 clientIf=8 错误?
- java - 带有 ActionListener 的多个 JComboBox
- excel - 如何从excel表的每一行生成pdf
- c# - 如何在c#中使用Zxing安排二维码的定位
- sql - 如何显示与成员对应的指定角色
- python - 如何将字典转换为键值为新列的数组
- swift - 复制或分配时,数组如何快速深度复制自身
- javascript - 如何使用 DataTables 获取行值和删除数据?
- google-app-engine - Stackdriver Trace 与 Google App Engine Go 1.11 运行时