我需要绑定HttpWebRequest的本地ip地址(机器有多个ip)。我创建了委托方法,这个方法被调用,并且为没有代理的请求绑定ip,但是一旦我向请求添加了代理详细信息,回调就再也不会发生了
如何绑定使用代理的HttpWebRequests的传出ip地址?
static void MakeRequest(string url, WebProxy myProxy)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.ServicePoint.BindIPEndPointDelegate = new BindIPEndPoint(BindIPEndPointCallback);
request.Proxy = myProxy;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
}
public static IPEndPoint BindIPEndPointCallback(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount)
{
// not called when proxy is set
Console.WriteLine("BindIPEndpoint called");
return new IPEndPoint(IPAddress.Parse("192.168.1.58"), 5000);
} 有没有其他的方法来绑定https?
发布于 2010-03-10 10:56:44
要绑定使用代理的请求,请使用ServicePointManager.FindServicePoint;
static void MakeRequest(string url, WebProxy myProxy)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Proxy = myProxy;
ServicePoint sp = ServicePointManager.FindServicePoint(new Uri(url), myProxy);
sp.BindIpEndPointDelegate = new BindIpEndPoint(BindIpEndPointCallback);
HttpWebResponse = (HttpWebResponse)request.GetResponse();
}适用于http请求,遗憾的是,在https请求上仍然不调用委托。
https://stackoverflow.com/questions/2384673
复制相似问题