2

I know how to POST regular data, but not sure how to POST an XML file to a public web service that requires it. Using Asp.net. Are there several ways? Choose best practice.

1
  • This really depends on the Web Service, if it's a public service could you post a link to the specifications for it? Commented Nov 30, 2009 at 20:06

2 Answers 2

2

If it's not a SOAP Web Service then something like this should work...

string xml = "<xmldoc />"; //your XML
string webservice = "http://mywebservice.com";
System.Net.WebRequest webreq = System.Net.WebRequest.Create(webservice);
webreq.Method = "POST";
webreq.ContentType = "text/xml";
System.IO.StreamWriter writer = new System.IO.StreamWriter(webreq.GetRequestStream());
writer.WriteLine(xml);
writer.Close();
System.Net.WebResponse webrsp = webreq.GetResponse();
string result = webrsp.ToString();
Sign up to request clarification or add additional context in comments.

Comments

0

They will probably have a form variable that you will put your whole XML string into. For example if they had a form variable named xmlData, you would set that value in your post to equal your whole xml file and then post it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.