2014-04-02 41 views
0

我正在嘗試使用cURL創建包含拉丁字符但沒有成功的CouchDB文檔。CouchDB錯誤:使用cURL的JSON中的拉丁字符

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 

回答

1

您發送JSON,所以讓服務器知道您發送的內容。只需添加這頭與你的curl命令:

-H 'Content-Type: application/json; charset=utf-8' 

此外,添加-v選項來查看捲曲調試消息。如果上述不起作用,則向我們顯示調試消息。

更新::我認爲服務器在解析JSON時會面臨問題。我對此不太瞭解,但可能將Nóthing更改爲N&oacute;thingN\u0443thing

+0

這不能解決它。我想這個錯誤表明它已經知道它是JSON。 – kubuntu

+0

我添加了調試消息。謝謝 – kubuntu

+0

試試'Content-Type:application/json; charset = utf-8'或你的字符集。它適用於我的測試服務器。 –