1: Create a WebRequest object using System.Net.WebRequest's Create method :
System.Net.WebRequest objwebrequest=system.net.webrequest.create (URLP);
Exception type:
The request scheme specified in Notsupportedexception:requesturi is not registered.
Argumentnullexception:requesturi is a null reference (Nothing in Visual Basic).
The SecurityException caller does not have permission to connect to the requested URI or to the URI on which the request is redirected.
2: Pre-authentication of the request, if there is no clear requirement, this item can be empty.
Objwebrequest.credentials=credentialcache.defaultcredentials;
If you need to follow a special authentication protocol, you need to cast to the HttpWebRequest type:
((HttpWebRequest) objwebrequest). Useragent= "5do8";
3: Specify the type of protocol:
Objwebrequest.method= "POST";
Can be post and get mode.
4: Send the transmission data length (if no display transmission, can also send), if set this entry, the data sent must exactly meet this value.
Objwebrequest.contentlength=stringdata.tochararray (). Length;
5: Set the MIME content type of the incoming request :
ObjWebRequest.ContentType="application/x-www-form-urlencoded";//Post
ObjWebRequest.ContentType="text/xml";//SOAP
6: Use the GetRequestStream () method to get the handle of the sent stream:
System.IO.Stream Datastream=objwebrequest.getrequeststream ();
7: Send the data :
Datastream.write (bytearray,0,bytearray.length);
Note: ByteArray is a byte array, and its fetch can be:
Byte[] Bytearray=utf8encoding.getbytes (DATAP);