Reputation: 2535
I am trying to create a CouchDB document that contains Latin characters using cURL without success.
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'
The response is {"error":"bad_request","reason":"invalid_json"}
.
However, the following works
curl -X PUT 'http://localhost:5984/example/1' -d '{"title":"There is Nothing Left to Lose","artist":"Foo Fighters"}' -H 'Content-Type: application/json'
The only difference is ó
in Nothing
.
Complete debug message:
* 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
Upvotes: 0
Views: 644
Reputation: 39365
You are sending JSON, so let the server know what you are sending. Just add this header with your curl command:
-H 'Content-Type: application/json; charset=utf-8'
Also, add -v
option to see the curl debug message. If above doesn't work, then show us the debug messages.
Update:: I think the server faces problem while parsing the JSON
. I don't much idea about this, but probably changing the Nóthing
into Nóthing
or N\u0443thing
.
Upvotes: 1