C# 如何通过特定ip地址发送httpwebrequests

C# 如何通过特定ip地址发送httpwebrequests,c#,httpwebrequest,ip,C#,Httpwebrequest,Ip,昨天,我收到一封邮件,宣布AmazonEC2的小实例最多可以有8个IP地址 比方说,我正在其中一个实例上运行应用程序。我正在使用httpwebrequest访问网站。如何控制请求来自哪个IP?来自哪个IP 好啊我从这里得到了答案。谢谢大家: HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://stackoverflow.com"); req.ServicePoint.BindIPEndPointDelegate = de

昨天,我收到一封邮件,宣布AmazonEC2的小实例最多可以有8个IP地址

比方说,我正在其中一个实例上运行应用程序。我正在使用httpwebrequest访问网站。如何控制请求来自哪个IP?

来自哪个IP


好啊我从这里得到了答案。谢谢大家:
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);