c# - how to change originating IP in HttpWebRequest -
I am running this application on a server that has appointed 5 IPs. I use HttpWebRequest to fetch some data from the website. But when I make the connection, then I am able to specify which connections from 5 IPs to make connections. Does HttpWebRequest support this? If it does not happen, can I change the behavior of a class by changing it? I need such ideas.
My code is just something like this:
System.Net.WebRequest request = System.Net.WebRequest.Create (link); (HttpWebRequest) request .referer = "http://application.com"; (Using System.Net.WebResponse response = request.GetResponse ()) {StreamReader sr = New StreamReader (response.GetResponseStream ()); Return sr.ReadToEnd (); }
According to, you may have to drop down to use sockets That is where I know that you can choose local IP.
EDIT: In fact, it seems that it could be possible. HttpWebRequest has a servicepoint property, which is in turn, which may be what you are looking for.
Give me one minute, I press an example ...
HTTP WebBridge Rick = (HTTP WebBurm) WebRequest. ("Http://stackoverflow.com"); Req.ServicePoint.BindIPEndPointDelegate = Representative (Servicepoint ServicePoint, IPEdpoint RemotePoint, Int Retriequate) {if (RemotepointPoint AddressFamily == System.Net.Sockets.EdressFamily.Internetworkwork6) {New IPPpoint (IPADrace IPv6Anne, 0); } And {new IPPpoint (IPadation Any, 0); }}; Console.WriteLine (req.GetResponse () ResponseUri.); In reality, the representative will have to return an IPEndPoint, whatever you want, but if he can not force it, then he will be able to return the representative again, int.MAX_VALUE Will call for time. This is the reason I included the code to handle IPv6, because IPAddress.Any is IPv4. If you do not care about IPv6, then you can get rid of it. Besides, I leave the IPADress's real challenge as an exercise to the reader :)
< / Div>
Comments
Post a Comment