2011-04-01 67 views

回答

7

我相信你可以通過提供BindIPEndPointDelegate來強制本地端點,該端口提供IP /端口綁定。

string sendingIp = "192.168.0.1"; 
int sendingPort = 5000; 
Uri uri = new Uri("http://google.com"); 
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(uri); 
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(); 

此代碼不處理正確處理。

+0

我可以在java中得到類似的東西嗎? – Nayn 2011-06-17 02:38:40