首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用PHP编写自由基cURL和mqlwrite

用PHP编写自由基cURL和mqlwrite
EN

Stack Overflow用户
提问于 2010-09-07 08:04:17
回答 1查看 283关注 0票数 2

嗨,我正在Freebase沙箱上做一些测试,但是我不能让下面的请求起作用。它挂了很久,然后什么回报也没有。我还输出了curl_getinfo(),如果它帮助任何人找出我出错的地方。

代码语言:javascript
复制
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;

输出

代码语言:javascript
复制
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
)

提前感谢您的帮助!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-09-07 10:36:41

最后,我把数据发送到freebase的方式成了一个问题。有一次我

代码语言:javascript
复制
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);

一切都很顺利。

这很奇怪,因为只有当我将数据作为post变量发送并将内容添加到请求的查询字符串时,它才能正常工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3656831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档