CouchDB cURL Windows Command Line Invalid JSON

Running the following command from a Windows command line using cURL attempting to post a new document to an existing CouchDB database (named test) fails:

curl -H "Content-Type: application/json" -X POST "http://127.0.0.1:5984/test" -d {"valid":"json"}

It returns the error:

{"error":"bad_request","reason":"invalid_json"}

The JSON is valid so what gives?


The answer is related to the formatting of the JSON string on the command line. Even though it is proper JSON when you type it, the command line, it seems, must reformat it before sending it.(Maybe someone else can explain why it does this in more detail.) To fix this you need to escape your quotations in the command line like so:

curl -H "Content-Type: application/json" -X POST "http://127.0.0.1:5984/test" -d {"""valid""":"""json"""}

See the extra quotation marks? This should work and return "ok:true" with an id and revision number.


你还必须引用整个声明来支持如下的空格:-d“{”title “:”没有什么可以丢失的“,”艺术家“:”Foo Fighters “}”“

链接地址: http://www.djcxy.com/p/1326.html

上一篇: 传递一个带括号的URL来卷曲

下一篇: CouchDB cURL Windows命令行无效的JSON