How to send double quote in -d parameter for curl.exe?

Show Details

Solution 1: [1]

My curl.exe works with this form:

-d "{\"param\":\"value\"}"

i.e. doublequotes around data, and doublequotes masked with backslash inside


Solution 2: [2]

You can most certainly escape double quotes. How you do that depends on your operating system and shell, which you fail to specify. On Windows, you'd use the ^ as the escape character.

You can also do this:

curl [...] -d @filename 

...which reads post data from a file called filename.

Google and/or man is your friend.

http://curl.haxx.se/docs/manpage.html


Solution 3: [3]

For the escaping of double quote question, I'm finding that tripling the doublequotes works from the shell:

curl -d {"""foo""":"""bar"""}

while doubling the doublequotes works from within a batch file:

curl -d {""foo"":""bar""}

Which is quite annoying for testing in the shell first.


Solution 4: [4]

You can surround the data with single quotes and use double quotes inside.

Example in PowerShell

curl.exe https://httpbin.org/anything `
    -H 'Content-Type: application/json' `
    -d '{ "this": "is proper json" }'.Replace('"', '""')

Please note that cURL is built into Windows 10, but PowerShell shadows it with an alias, so you have to use curl.exe


Solution 5: [5]

There is something called dollar slashy string.

def cmd = $/ curl -d '{"param":"value"}' -X POST https://example.com/service /$
sh cmd


Credits

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Credit
Solution 1 Alexander Chuprin
Solution 2 martona
Solution 3 Gaz
Solution 4 Isac
Solution 5 Anand Rockzz