<%@ Page Language="C#" AutoEventWireup="true" CodeFile="daili.aspx.cs" Inherits="daili" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>测试代理访问网站</title>
</head>
<body>
<form id="form1" runat="server">
<div>
测试代理访问网站
<br />
代理IP:<asp:TextBox ID="ProxyAddress" runat="server"></asp:TextBox>
<br />
端口号:<asp:TextBox ID="ProxyPort" runat="server"></asp:TextBox>
<br />
访问网站:<asp:TextBox ID="Address" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="访问" OnClick="Button1_Click" />
<br />
</div>
<div id="show" runat="server"></div>
</form>
</body>
</html>
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class daili : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(Address.Text);
hwr.Timeout = 60000;
WebProxy proxy = new WebProxy();
proxy.Address = new Uri(string.Format("http://{0}:{1}", ProxyAddress.Text, ProxyPort.Text));
hwr.UseDefaultCredentials = true;
hwr.Proxy = proxy;
hwr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
try
{
HttpWebResponse hwrs = (HttpWebResponse)hwr.GetResponse();
var htmlStream = new StreamReader(hwrs.GetResponseStream(), System.Text.Encoding.UTF8, true);
show.InnerHtml= htmlStream.ReadToEnd();
}
catch(Exception e1)
{
show.InnerHtml =string.Format("<span style='color:red'>{0}</span>{1},{2}",e1.Message, "获取失败!",DateTime.Now);
}
}
}
版权所有:有信心——uxinxin 我的个人网站欢迎常来!手机版(新站开启,请多多关照) 豫ICP备12017930号-1
豫公网安备 41910102000493号