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?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With