5

I need to post XML data via curl.exe under windows using PUT request.

In the curl help I found:

-d/--data <data>   HTTP POST data (H)

What should I supply for <data>?

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
sergtk
  • 10,714
  • 15
  • 75
  • 130
  • 2
    Haven't used curl with this option, but according to manual, it is simply string that is passed to the server as entity body. If your data starts with '@', then what follows is name of file that will be read and sent to the server. Check man page: http://curl.haxx.se/docs/manpage.html – Peter Štibraný Nov 23 '10 at 15:18
  • @Peter Štibraný Thanks! overlooked this - though that this is something specific for unix command line syntax and there is no in windows. – sergtk Nov 23 '10 at 15:25

4 Answers4

17

curl sample calls

# with inlining plain data
curl -X PUT -d "payload" http://localhost
# referrring file
curl -X PUT -d @myXmlFile.xml http://localhost

If your windows curl-port does not support it go for cygwin. It is a linux-like environment for windows and also offers "a proper" curl.

manuel aldana
  • 15,650
  • 9
  • 43
  • 50
  • I tried cygwin and obtained error with getaddrinfo. Ran on other PC - all ok. – sergtk Nov 25 '10 at 23:48
  • so this then looks like a problem with your machine or network stack? The other PC which OS is it, also windows? – manuel aldana Nov 26 '10 at 10:38
  • I struggled with posting data payload from file on windows too and in the end I found my data file was in UTF8 (starting with FF FE bytes) so I had to use `--data-binary` instead of just `-d` (which is alias for `--data`). – eXavier Mar 03 '14 at 12:31
  • on Windows PowerShell curl refers to Invoke-WebRequest which does not work as expected because it has a different syntax. Instead curl.exe is the Windows equivalence of Unix curl command and works as expected. – Saeed Mohtasham Jun 27 '22 at 12:14
7

in windows you'll need to put the @ inside the quotes for the file you're sending:

curl -XPUT --data-binary "@uploadme.txt"

otherwise you'll get weird errors as it tries to use the content of the file as the url:

curl: (6) Couldn't resolve host 'upload'
curl: (6) Couldn't resolve host 'me!'

(uploadme.txt contains "upload me!")

Paul Adamson
  • 2,011
  • 2
  • 18
  • 22
  • 2
    It was the putting of the @ insde the quotes that's had me guessing for hours. Thanks Paul – Martin Parry Apr 12 '17 at 02:09
  • 2
    Thanks for specifying that the @ needed to be put inside the quotes. I've been banging my head on the keyboard for the past few hours trying to figure this out. Thanks again – Mike Barlow - BarDev Oct 06 '17 at 19:09
7

In windows, if a double-quoted argument itself contains a double quote character, the double quote must be doubled.

For example, enter 'This is "quoted" payload' as "This is ""quoted"" payload" which is very different than in Unix.

Example:

curl -X PUT -d "This is ""quoted"" payload" http://localhost
Stefan
  • 1,036
  • 1
  • 10
  • 14
0

on Windows CMD, curl refers to C:\Windows\System32\curl.exe so you can use

curl -X PUT -d "payload" http://localhost

instead on Windows PowerShell curl refers to Invoke-WebRequest so it is not working with curl syntax. you can use curl.exe on PowerShell to call C:\Windows\System32\curl.exe so it will solve the issue.

curl.exe -X PUT -d "payload" http://localhost
Saeed Mohtasham
  • 1,693
  • 16
  • 27