Use the WebClient and WebRequest class to obtain the webpage source code

Source: Internet
Author: User

GetURLHtml. aspx
<% @ Page language = "c #" Codebehind = "GetURLHtml. aspx. cs "Src =" GetURLHtml. aspx. cs "AutoEventWireup =" false "Inherits =" Lion. web. forum. webForm1 "%>
<HTML>
<HEAD>
<Title> Lion interactive network => use the WebClient and WebRequest classes to obtain the webpage Source Code </title>
<META http-equiv = "Content-Type" content = "text/html; charset = gb2312">
</HEAD>
<Body>
<Form runat = "server">
<Asp: TextBox id = "UrlText" runat = "server" Width = "50%"> http://www.lionsky.net/mywebsite/index.aspx </asp: TextBox>
<Asp: Button id = "Button1" runat = "server" Text = "Get With WebClient"> </asp: Button> & nbsp;
<Asp: Button id = "Button2" runat = "server" Text = "Get With WebRequest"> </asp: Button> <BR>
<Asp: TextBox id = "ContentHtml" runat = "server" Width = "100%" Height = "360px" TextMode = "MultiLine"> </asp: TextBox>
</Form>
</Body>
</HTML>
GetURLHtml. aspx. Cs
Using System;
Using System. Collections;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Web;
Using System. Web. SessionState;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. HtmlControls;
Namespace Lion. Web. Forum
{
/// <Summary>
/// Summary of WebForm1.
/// </Summary>
Public class WebForm1: System. Web. UI. Page
{
Protected System. Web. UI. WebControls. TextBox TextBox1;
Protected System. Web. UI. WebControls. Button Button1;
Protected System. Web. UI. WebControls. Button Button2;
Protected System. Web. UI. WebControls. TextBox UrlText;
Protected System. Web. UI. WebControls. TextBox ContentHtml;
Protected System. Web. UI. WebControls. TextBox TextBox2;

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.