SoFunction
Updated on 2025-03-10

Read remote web page source code using HttpWebRequest

Read remote web page source code using HttpWebRequest

Updated: March 26, 2016 15:38:17 Author: haishu
This article shares a case of using HttpWebRequest to read remote web pages for your reference and learning.

There is no need to say more about what you can do when reading a remote web page. It’s all about doing thieves programs or collecting them.

public string GetPage(string url)
{

  HttpWebRequest request = null;

  HttpWebResponse response = null;

  StreamReader reader = null;

  try
  {

    request = (HttpWebRequest)(url);

     = 20000;

     = false;

    response = (HttpWebResponse)();

    if ( ==  &&  < 1024 * 1024)
    {

      reader = new StreamReader((), );

      string html = ();

      return html;

    }

  }

  catch
  {

  }

  finally
  {

    if (response != null)
    {

      ();

      response = null;

    }

    if (reader != null)

      ();

    if (request != null)

      request = null;

  }

  return ;
}

  • HttpWebRequest
  • Web page
  • Source code

Related Articles

  • New experiences with Gridview line binding events

    Recently, I have been counting the sum of a column in a GridView. I have added one by one in the RowDataBound event before. After testing, I found out that this is incorrect and cannot get the sum of all data.
    2009-11-11
  • Implementation principle and code in using JavaScript to display information prompt window

    When using JavaScript to display information window, interested friends can learn about it. This article will introduce detailed operation steps. I hope it will be helpful for consolidating your JavaScript knowledge
    2013-01-01
  • Another use of dataview for infinite classification

    Usually, when I saw others and myself binding the Infinitus classification, they always needed to connect to the database multiple times, which felt that it caused a waste of resources. Then I wanted to take out all the data at once (there was not a lot of types), which could save server overhead.
    2009-11-11
  • [Core] Use Blazor Server Side to implement image verification code

    This article mainly introduces how to use Blazor Server Side to implement image verification code. The explanation in the article is very detailed. The code helps everyone better understand and learn. Interested friends can learn about it.
    2020-07-07
  • Programmatically obtain the project root directory implementation method collection

    This article mainly introduces the implementation method of programming to obtain the project root directory, and combines the example form to analyze and summarize the operation skills and precautions for the project directory. Friends who need it can refer to it
    2015-11-11
  • .NET WeChat official account development for query custom menu

    This article tells you the third article in the .NET WeChat official account development series, which mainly explains the relevant content of querying custom menus. Friends who need it can refer to it.
    2015-07-07
  • Four verification programming methods for MVC

    MVC uses Model binding as the target Action to generate a corresponding parameter list, but before actually executing the target Action method, it is necessary to verify the bound parameters to ensure their validity. We will make the verification of the parameters a Model binding. Friends who need it can refer to it.
    2015-10-10
  • Use jQuery Uploader to display file upload progress

    When uploading large files, we all hope to show the upload progress to the user. So what we introduced here is to use jQuery Uploader to achieve this effect
    2011-12-12
  • Generate high-quality thumbnails general functions (c# code), support multiple generation methods

    In the past two days, we are studying the drawing methods of pie charts in reports, and some of the practices in the article are worth referring to.
    2008-08-08
  • Solutions to the problem of secondary domain name cookies

    Today, after the blog park fully adopted the second-level domain name, it was found that even if the user has logged in, it was not logged in when accessing the second-level domain name Blog page (it was shown that it was required to enter the verification code when posting a comment, and the collection function could not be used normally). After logging in again, you still need to log in to other second-level domain names.
    2008-10-10

Latest Comments