将資料作為XML資料發送,例如:

public void PostXml(string url, string xml)
{
byte[] bytes = Encoding.UTF8.GetBytes(xml);
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
request.Method = "POST";
request.ContentLength = bytes.Length;
request.ContentType = "text/xml";
using (Stream requestStream = request.GetRequestStream()) {
requestStream.Write(bytes, 0, bytes.Length);
}
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
if (response.StatusCode != HttpStatusCode.OK) {
string message = String.Format("POST failed. Received HTTP {0}",
response.StatusCode);
throw new ApplicationException(message);
}
接收端通過Request.InputStream讀取:

byte[] byts = new byte[Request.InputStream.Length];

Request.InputStream.Read(byts,0,byts.Length);

string req = System.Text.Encoding.Default.GetString(byts);

req = Server.UrlDecode(req);
對于完整的XML資料,可以:

xmlDoc = new XmlDocument();

xmlDoc.load(Request.InputStream);
本文轉自左正部落格園部落格,原文連結:http://www.cnblogs.com/soundcode/archive/2013/03/18/2966096.html,如需轉載請自行聯系原作者