Http Post Request Message Body中的C#Xml

我正在寻找一个示例,在C#中如何将xml文档放在http请求的消息体中,然后解析响应。 我已经阅读了文档,但我想看一个例子,如果有一个可用的。 有没有人有例子?

谢谢

private static string WebRequestPostData(string url, string postData) { System.Net.WebRequest req = System.Net.WebRequest.Create(url); req.ContentType = "text/xml"; req.Method = "POST"; byte[] bytes = System.Text.Encoding.ASCII.GetBytes(postData); req.ContentLength = bytes.Length; using (Stream os = req.GetRequestStream()) { os.Write(bytes, 0, bytes.Length); } using (System.Net.WebResponse resp = req.GetResponse()) { if (resp == null) return null; using (System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream())) { return sr.ReadToEnd().Trim(); } } } 

您应该使用WebRequest类。

这里有一个带注释的示例可用于发送数据:

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