json - Cloudant NoSql Bluemix 内容类型错误 : bad_content_type

标签 json zend-framework curl 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 ... 
    ]

所以我想将它发送到带有函数的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/

相关文章:

php - 将 Zend Framework 从版本 X 升级到版本 Y

php - 用 Zend 实现文件上传进度

java - 正确执行cURL请求

python - 连接/合并每个 Json 文件,python

php - 使用 Zend_Db 时如何将值设置为 NULL

javascript - 将数组转换为 JSON 以检查值

java - 我如何在 Java 中执行以下 curl 命令

php - 放置在网页上的未经授权的代码

PHP - json_decode - 解码字符串问题

javascript - 如何使用javascript将json数据从一个html页面传递到另一个html页面?