【发布时间】:2011-05-02 18:28:49
【问题描述】:
我有两个无线网络适配器连接到我的计算机,每个都连接到不同的网络。我想构建一种代理服务器,我的浏览器将连接到它,它会从不同的适配器发送 HTTP 请求,因此网页上的加载时间会更短。 你们知道如何决定从哪个网络适配器发送 HttpWebRequest 吗?
谢谢:)
更新
我使用了这个代码:
public static IPEndPoint BindIPEndPointCallback(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount)
{
List<IPEndPoint> ipep = new List<IPEndPoint>();
foreach (var i in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
{
foreach (var ua in i.GetIPProperties().UnicastAddresses)
ipep.Add(new IPEndPoint(ua.Address, 0));
}
return new IPEndPoint(ipep[1].Address, ipep[1].Port);
}
private void button1_Click(object sender, EventArgs e)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://whatismyip.com");
request.ServicePoint.BindIPEndPointDelegate = new BindIPEndPoint(BindIPEndPointCallback);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
string x = sr.ReadToEnd();
}
但即使我发送的 IPEndPoint 发生了变化,我从 WhatIsMyIp 获得的 IP 仍然相同.. 有什么帮助吗?
【问题讨论】:
-
您是否通过代理连接?
标签: c# httpwebrequest