如何让HttpWebRequest使用指定网络接口传输数据

using System; using System.Net; class Program { public static void Main () { foreach (var ip in Dns.GetHostAddresses (Dns.GetHostName ())) { Console.WriteLine ("Request from: " + ip); var request = (HttpWebRequest)HttpWebRequest.Create ("http://ns1.vianett.no/"); request.ServicePoint.BindIPEndPointDelegate = delegate { return new IPEndPoint (ip, 0); }; var response = (HttpWebResponse)request.GetResponse (); Console.WriteLine ("Actual IP: " + response.GetResponseHeader ("X-YourIP")); response.Close (); } } }

你可能感兴趣的:(request)