curl / Mailing Lists / curl-users / Single Mail

curl-users

Re: Windows cURL JSON POST sysntax

From: Ray Satiro via curl-users <curl-users_at_cool.haxx.se>
Date: Thu, 29 Dec 2016 18:20:33 -0500

On 12/29/2016 5:34 PM, Vince Hurst wrote:
>
> I've got a problem with possibly forming the correct syntax to send a
> JSON POST. This is only the case using the Windows versions of cURL.
> When I use Linux, there's no problem.
>
>
> I'm using the following:
>
> curl --trace log.txt -H "Content-Type: application/json" -d
> '{"recipients": ["1234567890"],"message": "Hello World"}'
> _http://172.21.20.120/api/sms/outbox?token=184D57B32AB68DC7784A32C9CDC456C_
>
>
> I get the following error:
>
> ----------------------------------------------------------------------------------------------
>
> curl: (3) [globbing] bad range in column 2
> curl: (3) [globbing] unmatched close brace/bracket in column 11
> HTTP/1.1 400 Bad Request
> Content-type: application/json
> Transfer-Encoding: chunked
> Date: Thu, 29 Dec 2016 21:12:35 GMT
> Server: rcell
>
> {
> "code" : 400,
> "error" : "json parser: * Line 1, Column 1\n Syntax error: value,
> object or
> array expected.\n* Line 1, Column 1\n A valid JSON document must be
> either an a
> rray or an object value.\n",
> "status" : "fail"
> }
>
> ----------------------------------------------------------------------------------------------
>
> Looking at the log file, the only JSON data is this: '{recipients:
>
>
> By removing all spaces within the JSON data, the log files show the
> full JSON data bein passed: '{recipients:[1234567890],message:HelloWorld}'
>

In the Windows command shell you have to use outer double quotes for the
string and escape any inner double quotes, for example

curl -H "Content-Type: application/json" -d "{\"recipients\":
[\"1234567890\"],\"message\": \"Hello World\"}" http://foo

It may be easier for you to put it in a file, for example

curl -H "Content-Type: application/json" --data-binary @filename http://foo

-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-users
FAQ: https://curl.haxx.se/docs/faq.html
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-12-30