Content-type not changing with CURLOPT_HTTPHEADERS

I am trying to send some kind of JSON to the cURL web service using the following code:

$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); 

In response, I get the following:

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

I found this blog post that seems to be related to it - it seems to be sending text/plain , although I have indicated ContentType in CURLOPT_HTTPHEADERS as application/json . But adding http_build_query did not help.

Thanks in advance for your help!

+6
json post php curl
source share
1 answer

I believe this should be HTTPHEADER , not HTTPHEADERS .

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

+10
source

All Articles