views:

3286

answers:

2

Hello,

I am looking for an example of how, in C#, to put a xml document in the message body of a http request and then parse the response. I've read the documentation but I would just like to see an example if there's one available. Does anyone have a example?

thanks

+1  A: 

You should use the WebRequest class.

There is an annotated sample available here to send data:

http://msdn.microsoft.com/en-us/library/debx8sh9.aspx

Mehrdad Afshari
+1  A: 
System.Net.WebRequest req = System.Net.WebRequest.Create("your url");

req.ContentType = "text/xml";
req.Method = "POST";

byte[] bytes = System.Text.Encoding.ASCII.GetBytes("Your Data");
req.ContentLength = bytes.Length;
os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length); 


System.Net.WebResponse resp = req.GetResponse();
if (resp == null) return;
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());

str responsecontent = sr.ReadToEnd().Trim();
Gratzy