asp.net to get the contents of a Remote Web page (downmoon original) _ Practical skills

Source: Internet
Author: User
Get one of the contents of a Remote Web page (downmoon original)
First, when the local direct access to the Internet:
Get the specified Remote Web page content #region get the specified remote Web page content
Copy Code code as follows:

/**////<summary>
Get the specified Remote Web page content
</summary>
<param name= "strURL" > The remote page address to look for </param>
<param name= "Timeout" > timeout length settings, generally set to 8000</param>
<param name= "Entertype" > Output line breaks, 0 not output, 1 output text box wrapping </param>
<param name= "Encodetype" > Coding mode </param>
<returns></returns>
You can also consider a 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

Second: Through the domain environment Agent online When this is not! The next article decomposition, hehe!

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.