- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用以下代码将一些 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
即使我已经指定了ContentType
在CURLOPT_HTTPHEADERS
如application/json
。但添加http_build_query
没有帮助。预先感谢您的帮助!
最佳答案
我相信它应该是HTTPHEADER
,而不是HTTPHEADERS
。
关于php - 内容类型不随 CURLOPT_HTTPHEADERS 改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4962871/
我正在尝试使用以下代码将一些 JSON 发布到带有 cURL 的 Web 服务: $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
我正在尝试使用以下代码通过 cURL 将一些 JSON 发布到 Web 服务: $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
我可以这样做吗? curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_slist_free_all(headerlist); 也就
除了使用 CURLOPT_HTTPHEADER 和 CURLOPT_USERPWD 为 cURL PHP 提供基本身份验证之外,还有其他替代方法吗? 我有一个超长的密码,所以 CURLOPT_USER
我可以调用curl_setopt吗?用 CURLOPT_HTTPHEADER 多次设置多个 header ? $url = 'http://www.example.com/'; $curlHandle
对于成功的 paypal 交易(没有 paypal-mock-response ),以下代码没有错误。 当我在 CURLOPT_HTTPHEADER 中添加 "PayPal-Mock-Response
我是一名优秀的程序员,十分优秀!