Asp. NET to send data as XML data using Request.inputstream receive

Source: Internet
Author: User

The

sends 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);
}
}
receive end read via 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 complete XML data, you can:
xmldoc = new XmlDocument ();
Xmldoc.load (Request.inputstream);

ASP. NET uses Request.inputstream to send data as XML data to receive

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.