How to POST a XML file using cURL?

17,694

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

Share:
17,694

Related videos on Youtube

woutr_be
Author by

woutr_be

Full stack product engineer with a passion for building great, user friendly products. I'm capable of building large front-ends and still be able to switch to working on back-ends with complex code bases.

Updated on September 30, 2022

Comments

  • woutr_be
    woutr_be over 1 year

    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?

  • woutr_be
    woutr_be almost 12 years
    Thanks a lot, that helped me out perfectly.
  • gorp88
    gorp88 over 5 years
    How to send xml attribute in curl request any ideas?
  • Flavio Cysne
    Flavio Cysne over 5 years
  • gorp88
    gorp88 over 5 years
    @flavio thank you, but I had resolved my issue using "\" escape character in xml string for attributes.