json - 在 CouchDB 中设置显式响应 Content-Type

标签 json couchdb

我正在寻找一种方法来设置 Contet-Type对于 couchdb 响应。

我有 POST使用 Content-Type 的 JSON和 Accept请求 header 为 application/json .但是当我调用 GET对于该文档,它返回带有 Content-Type 的 JSON 响应text/plain; charset=utf-8 .我期待的是得到 application/json因为它是 Content-Type .

我怎样才能做到这一点?

发布

  • 网址:http://localhost:5984/hotel_staticdata
  • 请求正文:{"_id":"test-hotel-stat-data","content":[{"hotelcode": "AMB3_LON","hotelname": "Ambassadors Bloomsbury"},{"hotelcode": "ALE1_LON","hotelname": "Alexandra"},{"hotelcode": "ALE1_LON","hotelname": "Alexandra"}]}
  • 请求 header :
    接受:应用程序/json
    内容类型:应用程序/json

  • 获取
  • 网址:http://localhost:5984/hotel_staticdata/test-hotel-stat-data
  • 回复正文:{"_id":"test-hotel-stat-data","_rev":"3-6c6e26cd5690794886a8dc65308bf078","content":[{"hotelcode":"AMB3_LON","hotelname":"Ambassadors Bloomsbury"},{"hotelcode":"ALE1_LON","hotelname":"Alexandra"},{"hotelcode":"ALE1_LON","hotelname":"Alexandra"}]}
  • 响应 header :
    内容长度:249
    内容类型:文本/纯文本;字符集=utf-8

  • 而不是这个,我尝试了 PUT 然后 GET ,但结果是一样的。
  • CouchDB 版本:1.6.1
  • 最佳答案

    我得到了答案。

    当我用 Accept:application/json 调用 GET 时请求 header 。有用!
    该死!我怎么错过了!

    无论如何,如果您有任何不同的解决方案,请随时发布。

    关于json - 在 CouchDB 中设置显式响应 Content-Type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42620627/

    相关文章:

    javascript - 在 couchdb 的 Javascript 查询中嵌入 JSON

    Python,CouchDb : how to Update already existing document by ID

    couchdb - Cloudant 和 CouchOne 之间的区别?

    javascript - 有没有好的方法来替换集合中的所有 couchDB 对象?

    php - FullCalendar 在月 View 中显示事件,但不在日、周或资源 View 中显示事件

    java - 如何扩展/编辑 Netbeans 自动生成的 REST 服务?

    json - elasticsearch请求数组中的元素

    Android Couchdb - libcouch 和 IPC Aidl 服务

    javascript - 通过表单发送json对象c# mvc

    json - 将配置文件与已编译的 Go 程序一起使用