Obtain remote file html

Source: Internet
Author: User
  
/// <Summary>
/// Obtain remote file html
/// </Summary>
/// <Param name = "url"> </param>
/// <Returns> </returns>
Public Static String remotehtml (string URL)
{
Try
{
Webrequest bi = Webrequest. Create (URL );
Webresponse GBI = Bi. getresponse ();
// In this case, the received data stream is received. Therefore, a streamreader is required to read the data and set the encoding format during reading. Generally, it is set to the default format ..
// To use streamreader, you need to add reference using system. IO;
Streamreader RBI = New Streamreader (GBI. getresponsestream (), system. Text. encoding. Default );
String Str = RBI. readtoend ();
Return STR;
}
Catch
{
Return "" ;
}
}

 

 

Set the target htmlCodeGet to page
/// <Summary>
/// Obtain the remote file html
/// </Summary>
/// <Param name = "url"> </param>
/// <Returns> </returns>
Public static string remotehtml (string URL)
{
Try
{
Webrequest Bi = webrequest. Create (URL );
Webresponse GBI = Bi. getresponse ();
// At this time, the received data stream is received. Therefore, a streamreader is required to read data and set the encoding format during reading. Generally, it is set to the default format ..
// You need to add reference using system. Io when using streamreader;
Streamreader RBI = new streamreader (GBI. getresponsestream (), system. Text. encoding. Default );
String STR = RBI. readtoend ();
Return STR;
}
Catch
{
Return "";
}
}

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.