通过特定的网络适配器发送的HttpWebRequest [英] Sending HttpWebRequest through a specific network adapter

查看:617
本文介绍了通过特定的网络适配器发送的HttpWebRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有连接到计算机的两个无线网络适配器,每个连接到不同的网络。我想营造一种代理服务器,我的浏览器将连接到它会发送的每个来自不同的适配器HTTP请求等网页加载时间会更小。
。你们知道我可以从网络适配器发送的HttpWebRequest

I have two wireless network adapters connected to my computer, each connected to a different network. I would like to build a kind of proxy server that my browser would connect to and it will send HTTP requests each from different adapter so loading time on webpages would be smaller. Do you guys know how can I decide from which network adapter to send the 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是还是一样的..任何帮助吗?

But even if a change the IPEndPoint I send the IP I get from WhatIsMyIp is still the same.. any help?

推荐答案

BindIPEndPointDelegate 可能是你在这里后,在做什么。它可以让你使用一个特定的IP是终点,通过它的HttpWebRequest发送。

BindIPEndPointDelegate may well be what you're after here. It allows you to force a particular local IP to be the end-point via which the HttpWebRequest is sent.

这篇关于通过特定的网络适配器发送的HttpWebRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆