C # Processing of data submitted to the server and returned

Source: Internet
Author: User

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);

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.