tags:

views:

698

answers:

2

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());
}
A: 

Have you tried url-encoding the data ? cURL can take care of that for you :

curl -H "text/xml" --data-urlencode "<XmlContainer xmlns='sads'..." http://myapiurl.com/service.svc/
defraagh
+3  A: 

-H "text/xml" isn't a valid header. You need to provide the full header:

-H "Content-Type: text/xml" 
Ben James
This did the trick
Jan Jongboom