Cloudant NoSql Bluemix内容类型错误:bad_content_type

cra*_*uba 2 json curl zend-framework cloudant ibm-cloud

有没有人遇到过这个错误?我已经在互联网上搜索了响应,甚至写信给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 ... 
    ]
Run Code Online (Sandbox Code Playgroud)

所以我想通过函数将其发送到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();
Run Code Online (Sandbox Code Playgroud)

我得到的回应是:

"error":"bad_content_type","reason":"Content-Type必须是application/json"

有没有人最近与Cloudant有这样的问题(昨天它工作正常)?我是否正确设置标头的Content-Typeapplication/json

Jef*_*yer 5

看起来你正在正确设置标题...我的猜测是你发布的对象不是JSON.尝试转换$obj为JSON.

使用以下代替 $client->setParameterPost($obj);

$client->setRawData(json.dumps($obj), 'application/json')
Run Code Online (Sandbox Code Playgroud)