gpt4 book ai didi

php - 内容类型不随 CURLOPT_HTTPHEADERS 改变

转载 作者:行者123 更新时间:2023-12-02 13:23:13 25 4
gpt4 key购买 nike

我正在尝试使用以下代码将一些 JSON 发布到带有 cURL 的 Web 服务:

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_URL, 'http://index.yolink.com/index/define?o=json&ak=APIKEY');
curl_setopt($ch, CURLOPT_HTTPHEADERS,array('Content-Type: application/json'));

$data = array(
'ignore-robots' => 'false',
'language' => 'english',
'crawl-delay' => '0',
'depth' => '3',
'root' => array('url' => 'http://bartleby.com/')
);

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$result=curl_exec($ch);
var_dump($result);

我得到以下返回:

string(282) "HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Access-Control-Allow-Origin: * Content-Type: text/plain Content-Length: 120 Date: Fri, 18 Mar 2011 19:03:23 GMT {"code":"error.indexdefinition.invalid","message":"Invalid content provided for /define. Error:Premature end of file.."}"

我找到了this blog post这似乎是相关的——它似乎确实正在发送 text/plain即使我已经指定了 ContentTypeCURLOPT_HTTPHEADERSapplication/json 。但添加 http_build_query没有帮助。

预先感谢您的帮助!

最佳答案

我相信它应该是HTTPHEADER,而不是HTTPHEADERS

http://php.net/manual/en/function.curl-setopt.php

关于php - 内容类型不随 CURLOPT_HTTPHEADERS 改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4962871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com