在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
//设置对外访问所使用网卡的IP string sendingIp = "192.168.0.1"; //设置对外访问所使用的端口 int sendingPort = 5000; Uri uri = new Uri("http://google.com"); HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(uri); //获取对外访问的包,并指定使用那个IP(网卡)与端口来发送数据包 ServicePoint sp = ServicePointManager.FindServicePoint(uri); sp.BindIPEndPointDelegate = (servicePoint,remoteEp,retryCount) => { return new IPEndPoint(IPAddress.Parse(sendingIp),sendingPort); }; //提交请求并获取返回结果 var data = new StreamReader(wr.GetResponse().GetResponseStream()).ReadToEnd(); //获取多网卡Ip
|
请发表评论