I want to post XML data with cURL. I don't care about forms like said in How do I make a post request with curl.
I want to post XML content to some webservice using cURL command line interface. Something like:
curl -H "text/xml" -d "<XmlContainer xmlns='sads'..." http://myapiurl.com/service.svc/
The above sample however cannot be processed by the service.
Reference example in C#:
WebRequest req = HttpWebRequest.Create("http://myapiurl.com/service.svc/"); req.Method = "POST"; req.ContentType = "text/xml"; using(Stream s = req.GetRequestStream()) { using (StreamWriter sw = new StreamWriter(s)) sw.Write(myXMLcontent); } using (Stream s = req.GetResponse().GetResponseStream()) { using (StreamReader sr = new StreamReader(s)) MessageBox.Show(sr.ReadToEnd()); }
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.
Users can send data with the POST request using the -d flag. The following POST request sends a user and a pass field along with their corresponding values. POSTing with curl's -d option will include a default header that looks like: Content-Type: application/x-www-form-urlencoded .
-H "text/xml"
isn't a valid header. You need to provide the full header:
-H "Content-Type: text/xml"
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