Webrequest request = Webrequest. Create ( " Http://www.contoso.com/PostAccepter.aspx " );
// Set the method property of the request to post.
Request. Method = " Post " ;
// Create post data and convert it to a byte array.
String Postdata = " This is a test that posts this string to a Web server. " ;
Byte [] Bytearray = Encoding. utf8.getbytes (postdata );
// Set the contenttype property of the webrequest.
Request. contenttype = " Application/X-WWW-form-urlencoded " ;
// Set the contentlength property of the webrequest.
Request. contentlength = Bytearray. length;
// Get the request stream.
Stream datastream = Request. getrequeststream ();
// Write the data to the request stream.
Datastream. Write (bytearray, 0 , Bytearray. Length );
// Close the stream object.
Datastream. Close ();
// Get the response.
Webresponse response = Request. getresponse ();
// Display the status.
Console. writeline (httpwebresponse) Response). statusdescription );
// Get the Stream Containing content returned by the server.
Datastream = Response. getresponsestream ();
// Open the stream using a streamreader for easy access.
Streamreader = New Streamreader (datastream );
// Read the content.
String Responsefromserver = Reader. readtoend ();
// Display the content.
Console. writeline (responsefromserver );
// Clean up the streams.
Reader. Close ();
Datastream. Close ();
Response. Close ();
Q.This is an example in msdn. It is okay to use this method to post general characters, but an XML string of post is as follows:
System. xml. xmldocument xmlpostdata = new system. xml. xmldocument ();
Xmlpostdata. Load ("D: \ SS \ test. xml ");
String postdata = xmlpostdata. innerxml;
In webresponse response = request. getresponse ();
Error message: webexceptionstatus protocolerror
A.Set string postdata = xmlpostdata. innerxml;
Change
String postdata = httputility. htmlencode (xmlpostdata. innerxml );