3

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>?

2
  • 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: 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
15

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.

3
  • 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 3 '14 at 12:31
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
6

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!")

2
  • 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 2: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 6 '17 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.