Send data as XML data, for example:
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 );
}
}
The receiving end reads data through 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 );
For the complete XML data, you can:
XmlDoc = new XmlDocument ();
XmlDoc. load (Request. InputStream );
From Yeju dongli