有人遇到过这个错误吗?我在互联网上搜索了回复,甚至写信给 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:
$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 must be application/json"
最近有人在使用 Cloudant 时遇到过此类问题吗(昨天还运行良好)?我是否正确设置了 application/json
的 header Content-Type
?
最佳答案
看来您正确设置了 header ...我的猜测是您发布的对象不是 JSON。尝试将 $obj
转换为 JSON。
使用以下内容代替$client->setParameterPost($obj);
$client->setRawData(json.dumps($obj), 'application/json')
关于json - Cloudant NoSql Bluemix 内容类型错误 : bad_content_type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29675643/