Receive post requests sent to the server

Source: Internet
Author: User

public string GetPage (string PostURL, String postdata)
Stream outstream = null;
Stream instream = null;
StreamReader sr = null;
HttpWebResponse response = null;
HttpWebRequest request = null;
Encoding Encoding = Encoding.UTF8;
byte[] data = encoding. GetBytes (PostData);
Prepare request ...
Setting parameters
Request = WebRequest.Create (PostURL) as HttpWebRequest;
Cookiecontainer Cookiecontainer = new Cookiecontainer ();
Request. Cookiecontainer = Cookiecontainer;
Request. AllowAutoRedirect = true;
Request. Method = "POST";
Request. ContentType = "application/x-www-form-urlencoded";
Request. ContentLength = data. Length;
OutStream = Request. GetRequestStream ();
OutStream. Write (data, 0, data. Length);
OutStream. Close ();
Send request and get corresponding response data
Response = Request. GetResponse () as HttpWebResponse;
Until request. The GetResponse () program only starts sending a POST request to the destination Web page
Instream = Response. GetResponseStream ();
sr = new StreamReader (instream, encoding);
Return result Web page (HTML) code
String content = Sr. ReadToEnd ();
string err = string. Empty;
return content;
catch (Exception ex)
string err = ex. Message;
Response.Write (ERR);
return string. Empty;

Receive post requests sent to the server

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: 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.