我有两个连接到我的计算机的无线网络适配器,每个都连接到不同的网络.我想构建一种我的浏览器将连接到的代理服务器,它将从不同的适配器发送每个HTTP请求,因此网页上的加载时间会更短.你们知道我如何决定从哪个网络适配器发送HttpWebRequest?
谢谢 :)
UPDATE
我用过这段代码:
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();
}
Run Code Online (Sandbox Code Playgroud)
但即使改变IPEndPoint我发送的IP我从WhatIsMyIp得到的仍然是相同的..任何帮助?