6

I'm using a web interface that allows me to post stuff over a cURL request.

A sample post looks like this:

<status>A note</status>

But whenever I try to send this, it seems to not accept the XML

curl http://website.com/update -d '<?xml version="1.0" encoding="UTF-8"?><status>test</status>' -H 'Accept: application/xml' \ -H 'Content-Type: application/xml'  -u username:password

I can do any other type of requests, just sending this XML doesn't seem to work, am I doing something wrong here?

2240
  • 1,547
  • 2
  • 12
  • 30
woutr_be
  • 9,532
  • 24
  • 79
  • 129
  • possible duplicate of [send/post xml file using curl command line](http://stackoverflow.com/questions/3007253/send-post-xml-file-using-curl-command-line) – dkinzer Nov 06 '14 at 21:02

1 Answers1

7

To send data (xml,json,text,etc) using curl you have to use POST method and add --data-urlencode parameter, like shown bellow:

curl -X POST http://website.com/update \
  --data-urlencode xml="<status>A note</status>" \
  -H 'Accept: application/xml' \
  -H 'Content-Type: application/xml' \
  -u username:password

or

curl -X POST http://website.com/update \
  --data-urlencode "<status>A note</status>" \
  -H 'Accept: application/xml' \
  -H 'Content-Type: application/xml' \
  -u username:password

If you want to send via GET i think you have to encode the string before calling curl command

heisian
  • 6,127
  • 1
  • 17
  • 17
Flavio Cysne
  • 1,436
  • 8
  • 8
  • How to send xml attribute in curl request any ideas? – gorp88 Oct 10 '18 at 20:39
  • @gorp88 you could try one of these answers: https://stackoverflow.com/questions/1880009/curl-sending-xml-incorrectly-when-using-tag-attributes https://superuser.com/questions/149329/what-is-the-curl-command-line-syntax-to-do-a-post-request – Flavio Cysne Oct 15 '18 at 13:20
  • @flavio thank you, but I had resolved my issue using "\" escape character in xml string for attributes. – gorp88 Oct 15 '18 at 21:59