我正在尝试使用cURL创建包含拉丁字符的CouchDB文档,但没有成功。
curl -X PUT 'http://localhost:5984/example/1' -d '{"title":"There is Nóthing Left to Lose","artist":"Foo Fighters"}' -H 'Content-Type: application/json'
回复是{"error":"bad_request","reason":"invalid_json"}
。
但是,以下工作
curl -X PUT 'http://localhost:5984/example/1' -d '{"title":"There is Nothing Left to Lose","artist":"Foo Fighters"}' -H 'Content-Type: application/json'
唯一的区别是ó
中的Nothing
。
完成调试消息:
* About to connect() to 127.0.0.1 port 5984 (#0)
* Trying 127.0.0.1...
* Adding handle: conn: 0x20a6050
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x20a6050) send_pipe: 1, recv_pipe: 0
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to localhost (127.0.0.1) port 5984 (#0)
> PUT /example/1 HTTP/1.1
> User-Agent: curl/7.30.0
> Host: localhost:5984
> Accept: */*
> Content-Type: application/json
> Content-Length: 65
>
} [data not shown]
* upload completely sent off: 65 out of 65 bytes
< HTTP/1.1 400 Bad Request
* Server CouchDB/1.4.0 (Erlang OTP/R14B04) is not blacklisted
< Server: CouchDB/1.4.0 (Erlang OTP/R14B04)
< Date: Wed, 02 Apr 2014 13:38:33 GMT
< Content-Type: text/plain; charset=utf-8
< Content-Length: 48
< Cache-Control: must-revalidate
<
{ [data not shown]
100 113 100 48 100 65 3000 4062 --:--:-- --:--:-- --:--:-- 65000
{"error":"bad_request","reason":"invalid_json"}
* Connection #0 to host 127.0.0.1 left intact
答案 0 :(得分:1)
您正在发送JSON,因此请让服务器知道您要发送的内容。只需使用curl命令添加此标头:
-H 'Content-Type: application/json; charset=utf-8'
另外,添加-v
选项以查看curl调试消息。如果以上不起作用,请向我们显示调试消息。
更新:: 我认为服务器在解析JSON
时会遇到问题。我对此并不太了解,但可能会将Nóthing
更改为Nóthing
或N\u0443thing
。