Get one of the remote webpage content (downmoon original)
1. When the local machine directly accesses the Internet:
Obtain the content of the specified remote webpage # region obtains the content of the specified remote webpage
Copy codeThe Code is as follows:
/** // <Summary>
/// Obtain the content of the specified remote webpage
/// </Summary>
/// <Param name = "strUrl"> remote webpage address to be searched </param>
/// <Param name = "timeout"> set the timeout period, which is generally set to 8000 </param>
/// <Param name = "enterType"> whether to output a line break. 0 indicates no output. 1 indicates a line break in the output text box. </param>
/// <Param name = "EnCodeType"> encoding method </param>
/// <Returns> </returns>
/// You can also consider static string
Public string GetRequestString (string strUrl, int timeout, int enterType, Encoding EnCodeType)
...{
String strResult;
Try
...{
HttpWebRequest myReq = (HttpWebRequest) HttpWebRequest. Create (strUrl );
MyReq. Timeout = timeout;
HttpWebResponse HttpWResp = (HttpWebResponse) myReq. GetResponse ();
Stream myStream = HttpWResp. GetResponseStream ();
StreamReader sr = new StreamReader (myStream, EnCodeType );
StringBuilder strBuilder = new StringBuilder ();
While (-1! = Sr. Peek ())
...{
StrBuilder. Append (sr. ReadLine ());
If (enterType = 1)
...{
StrBuilder. Append ("");
}
}
StrResult = strBuilder. ToString ();
}
Catch (Exception err)
...{
StrResult = "request error:" + err. Message;
}
Return strResult;
}
# Endregion
2. This will not work if you use a domain environment proxy to access the Internet! Next Article breakdown, haha!