您的位置:首页 > 产品设计 > UI/UE

利用WebClient和WebRequest类获得网页源代码

2007-11-29 22:21 405 查看
关键是ValidateRequest="false",要不然会说request.form,报错

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>无标题页</title>

</head>

<body>

<form id="form1" runat="server">

<div align="center" style="FONT-WEIGHT: bold">得到任意网页源代码</div>

<asp:TextBox id="UrlText" runat="server" Width="400px">http://boco.com.cn

</asp:TextBox>

<asp:Button id="WebClientButton" Runat="server" Text="用WebClient得到" OnClick="WebClientButton_Click"></asp:Button>

<asp:Button id="WebRequestButton" runat="server" Text="用WebRequest得到" OnClick="WebRequestButton_Click"></asp:Button>

<asp:Button ID="Button1" runat="server" OnClick="GetText_Click" Text="Button" /><br>

<asp:TextBox id="ContentHtml" runat="server" Width="100%" Height="360px" TextMode="MultiLine">

</asp:TextBox>

</form>

</body>

</html>

private string PageUrl = "";

protected void WebClientButton_Click(object sender, System.EventArgs e)

protected void WebRequestButton_Click(object sender, System.EventArgs e)

protected void GetText_Click(object sender, System.EventArgs e)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: