I want to make a web request from one of available IP addresses on server so I use this class:
public class UseIP
{
public string IP { get; private set;
I have changed your example a little and make it work on my machine:
public HttpWebRequest CreateWebRequest(Uri uri)
{
HttpWebRequest wr = WebRequest.Create(uri) as HttpWebRequest;
wr.ServicePoint.BindIPEndPointDelegate = new BindIPEndPoint(Bind);
return wr;
}
I did that because:
FindServicePoint
actually does the request using the "default" ip, without even calling the binding delegate, to the URI you have specified. In my machine, at least, the BindIPEndPointDelegate
was not called in the way you have presented (I know the request was made because I didn't set the Proxy and got a proxy authentication error);ServicePointManager
.