2012-07-08 78 views
0

昨天,我收到郵件,宣佈微型亞馬遜EC2實例最多可以有8個IP地址。如何通過特定的IP地址發送httpwebrequests

比方說,我正在其中一個實例上運行應用程序。我使用httpwebrequest訪問網站。我如何控制,請求來自哪個IP?

+0

確定服用。從這裏得到了我的答案。謝謝大家:http://stackoverflow.com/questions/3345387/how-to-change-originating-ip-in-httpwebrequest – 2012-07-08 15:37:35

回答

2

this question

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://stackoverflow.com"); 

req.ServicePoint.BindIPEndPointDelegate = delegate(
ServicePoint servicePoint, 
IPEndPoint remoteEndPoint, 
int retryCount) { 

if (remoteEndPoint.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) { 
    return new IPEndPoint(IPAddress.IPv6Any, 0); 
} else { 
    return new IPEndPoint(IPAddress.Any, 0); 
} 

}; 

Console.WriteLine(req.GetResponse().ResponseUri); 
相關問題