Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to POST a XML file using cURL?

Tags:

post

curl

xml

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?

like image 368
woutr_be Avatar asked May 17 '12 09:05

woutr_be


People also ask

How does Curl respond to XML?

To send XML to the server using Curl, you need to pass the XML data to Curl with the -d command line option and specify the data type in the body of the POST message using the -H "Content-Type: application/xml" command-line option.

How do I POST XML to the server?

To post XML data to the server, you need to make an HTTP POST request, include the XML in the body of the request message, and set the correct MIME type for the XML. The correct MIME type for XML is application/xml.

What is POST in Curl command?

HTTP POST - Everything curl. HTTP POST. POST is the HTTP method that was invented to send data to a receiving web application, and it is how most common HTML forms on the web works. It usually sends a chunk of relatively small amounts of data to the receiver.


1 Answers

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

like image 157
Flavio Cysne Avatar answered Nov 03 '22 16:11

Flavio Cysne