Reputation: 104
Has anyone encountered this error ? I have searched for the response on the internet, even wrote to IBM Cloudant support but nothing.
Yesterday it was working alright but now it's not working. I am using Zend Framework 1.12 and Zend_Http_Client_Adapter_Curl()
function to send POST
to the Cloudant database. I have an object :
PART OF OBJECT
$obj =
{"articles":[
{
"_id":"1100_20144071226",
"id":"1100_20144071226",
"title":"BLA BL BADASDSDDAS A BLA Native Advertising Shakes Up Agency And Brand Ecosystem",
"img":"http:\/\/s3.amazonaws.com\/static.mediapost.com\/publications\/images\/mp-logo-fb.jpg",
"titleOrg":null,
"description":"Brands such as <i class=\"highlight\">Pepsi<\/i>, Logitech,SONY, FOX, CBS, TiVo, Timberland, US Gov\'t and many more find complete, seamless satisfacting with HITVIEWS\' approach."
},
etc etc ...
]
So i want to send it to curl with function :
$curl = new Zend_Http_Client_Adapter_Curl();
$client = new Zend_Http_Client( $this->uri."/".$db );
$client->setAdapter( $curl );
$client->setMethod( Zend_Http_Client::POST );
$client->setParameterPost("_id", $obj['id']);
$client->setParameterPost($obj);
$client->setHeaders('Content-type' ,'application/json');
return print $response = $client->request()->getBody();
The response i'm getting is :
"error":"bad_content_type","reason":"Content-Type must be application/json"
Has anyone had this kind of problem with Cloudant lately (yesterday it was working fine)? Am I setting correctly header's Content-Type
for application/json
?
Upvotes: 2
Views: 201
Reputation: 4964
It looks like you are setting the header correctly... My guess is that the object you are posting isn't JSON. Try converting $obj
to JSON.
Use the following instead of $client->setParameterPost($obj);
$client->setRawData(json.dumps($obj), 'application/json')
Upvotes: 5