昨天,我收到了邮件,宣布微小的亚马逊EC2实例最多可以拥有8个IP地址。
让我们说,我正在其中一个实例上运行一个应用程序。我正在使用httpwebrequest来访问网站。我如何控制请求来自哪个IP?
答案 0 :(得分:2)
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);