使用 PHP 的 freebase cURL 和 mqlwrite

发布于 2024-09-17 11:40:28 字数 1734 浏览 9 评论 0原文

您好,我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沐歌 2024-09-24 11:40:28

这最终成为我向 freebase 发送数据的方式的问题。一旦我添加

curl_setopt($ch, CURLOPT_POSTFIELDS, $query);

它一切都很好。

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

It ended up being an issue with the way I was sending data to freebase. Once I added

curl_setopt($ch, CURLOPT_POSTFIELDS, $query);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文