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 ...
Try
{
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