Notes for using httpwebrequest

Source: Internet
Author: User

When using the post method to access the site, note that post must be in uppercase; otherwise, error 403 is reported.
For aspx web pages, you must pay attention to viewstate. If you do not post viewstate, the background program will not process it.

HttpWebRequest myHttpWebRequest =
(HttpWebRequest) WebRequest. Create ("http: // 192.168.31.20/action/WebForm1.aspx ");
MyHttpWebRequest. Method = "POST ";
String postData = "TextBox1 =" + textBox1.Text;
System. Text. ASCIIEncoding encoding = new System. Text. ASCIIEncoding ();
Byte [] byte1 = encoding. GetBytes (postData );
MyHttpWebRequest. ContentType = "application/x-www-form-urlencoded ";
MyHttpWebRequest. ContentLength = postData. Length;
System. IO. Stream newStream;
NewStream = myHttpWebRequest. GetRequestStream ();
NewStream. Write (byte1, 0, byte1.Length );
NewStream. Close ();
System. Net. WebResponse wResp = myHttpWebRequest. GetResponse ();
System. IO. Stream respStream = wResp. GetResponseStream ();
System. IO. StreamReader reader = new System. IO. StreamReader (respStream,

System. Text. Encoding. GetEncoding ("gb2312 "));
TextBox2.Text = reader. ReadToEnd ();
RespStream. Close ();
Reader. Close ();



Related Article

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.