有没有人遇到过这个错误?我已经在互联网上搜索了响应,甚至写信给IBM Cloudant支持但没有。
昨天它工作正常,但现在它没有用。我使用Zend Framework 1.12和Zend_Http_Client_Adapter_Curl()
函数将POST
发送到Cloudant数据库。我有一个对象:
对象的一部分
$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 ...
]
所以我想用函数发送它:
$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();
我得到的回应是:
“error”:“bad_content_type”,“reason”:“Content-Type必须是 应用/ JSON“
最近有没有人遇到Cloudant这样的问题(昨天它工作正常)?我为Content-Type
设置了正确的标题application/json
吗?
答案 0 :(得分:5)
看起来您正在正确设置标头...我的猜测是您发布的对象不是JSON。尝试将$obj
转换为JSON。
使用以下代替$client->setParameterPost($obj);
$client->setRawData(json.dumps($obj), 'application/json')