Code
Introduce namespace
Using System. IO;
Using System. net;
Using System. text;
Using System. Text. regularexpressions;
// Capture remote page content in get Mode
Public String Get_http ( String Turl)
{
String Strresult;
Try
{
Httpwebrequest HWR = (Httpwebrequest) httpwebrequest. Create (Turl );
HWR. Timeout = 19600 ;
Httpwebresponse hwrs = (Httpwebresponse) HWR. getresponse ();
Stream mystream = Hwrs. getresponsestream ();
Streamreader SR = New Streamreader (mystream, encoding. Default );
Stringbuilder sb = New Stringbuilder ();
While ( - 1 ! = Sr. Peek ())
{
SB. append (Sr. Readline () + " \ R \ n " );
}
Strresult = SB. tostring ();
Hwrs. Close ();
}
Catch (Exception ee)
{
Strresult = Ee. message;
}
Return Strresult;
}
// Capture remote page content in post Mode
// Postdata is the parameter list
Public String Post_http ( String URL, String Postdata, String Encodetype, Out String Err)
{
String Uristring = URL;
Byte [] Bytearray;
Byte [] Responsearray;
// Postdata = "checkvalue = 32 & BBB = % Cd % B6 % C6 % B1 & ILC = 0 & KKK = 22 ";
Encoding = Encoding. getencoding (encodetype );
Try
{
WebClient mywebclient = New WebClient ();
Webheadercollection mywebheadercollection;
Mywebclient. headers. Add ( " Content-Type " , " Application/X-WWW-form-urlencoded " );
// Mywebclient. headers. Add ("Referer "," Http: // XXXXX/xxxxxxxxxxxxxxxxxxxxxxxxxx ");
// Mywebclient. headers. Add ("Accept-language", "ZH-CN ");
Mywebheadercollection = Mywebclient. headers;
Bytearray = Encoding. getbytes (postdata );
Responsearray = Mywebclient. uploaddata (uristring, " Post " , Bytearray );
Err = String . Empty;
Return This . Strclearnouse (encoding. getstring (responsearray ));
}
Catch (Exception ex)
{
Err = Ex. message;
Return String . Empty;
}
}