使用 PHP 的 freebase cURL 和 mqlwrite
您好,我正在 Freebase 沙箱上进行一些测试,但我无法让以下请求正常工作。它挂起很长时间然后什么也不返回。我还输出了curl_getinfo(),如果它可以帮助任何人找出我出错的地方。
echo $uri = "http://".$this->config['apiSandboxHost'].'/'.$this->config['apiWritePath'].'={"create":"unless_exists","type":"/user/docs/music/note","name":"A","id":null}';
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$headers = array();
$headers[] = 'X-Metaweb-Request : idio';
$headers[] = 'Content-length: 78';
$headers[] = 'Content-type: application/x-www-form-urlencoded';
$headers[] = 'Cookie: '. implode(';', $this->authCookies);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec($ch);
pr(curl_getinfo($ch));
curl_close($ch);
echo $output;
输出
http://sandbox.freebase.com/api/service/mqlwrite?query={"create":"unless_exists","type":"/user/docs/music/note","name":"A","id":null}
Array
(
[url] => http://sandbox.freebase.com/api/service/mqlwrite?query={"create":"unless_exists","type":"/user/docs/music/note","name":"A","id":null}
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 693
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 285.371
[namelookup_time] => 0
[connect_time] => 0.185
[pretransfer_time] => 0.185
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => -1
[starttransfer_time] => 285.371
[redirect_time] => 0
)
预先感谢您的帮助!
Hi am doing some testing on the Freebase sandbox, but I can't get the following request to work. It hangs for ages then returns nothing. I have also outputted curl_getinfo() if it helps anyone work out where I am going wrong.
echo $uri = "http://".$this->config['apiSandboxHost'].'/'.$this->config['apiWritePath'].'={"create":"unless_exists","type":"/user/docs/music/note","name":"A","id":null}';
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$headers = array();
$headers[] = 'X-Metaweb-Request : idio';
$headers[] = 'Content-length: 78';
$headers[] = 'Content-type: application/x-www-form-urlencoded';
$headers[] = 'Cookie: '. implode(';', $this->authCookies);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec($ch);
pr(curl_getinfo($ch));
curl_close($ch);
echo $output;
Output
http://sandbox.freebase.com/api/service/mqlwrite?query={"create":"unless_exists","type":"/user/docs/music/note","name":"A","id":null}
Array
(
[url] => http://sandbox.freebase.com/api/service/mqlwrite?query={"create":"unless_exists","type":"/user/docs/music/note","name":"A","id":null}
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 693
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 285.371
[namelookup_time] => 0
[connect_time] => 0.185
[pretransfer_time] => 0.185
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => -1
[starttransfer_time] => 285.371
[redirect_time] => 0
)
Thanks in advance for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这最终成为我向 freebase 发送数据的方式的问题。一旦我添加
它一切都很好。
这很奇怪,因为只有当我将数据作为 post 变量发送并将内容添加到请求的查询字符串中时,我才能使其正常工作。
It ended up being an issue with the way I was sending data to freebase. Once I added
it all worked fine.
It was weird as I could only get it working when I sent the data as a post variable and also added content to the query string of the request.