One of the remote webpage content retrieved in asp.net (original downmoon)

Source: Internet
Author: User

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!

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.