How to Specify WebRequest IP to use (or HttpWebRequest if applicable) (C#)
Is it possible to specify the IP address a WebRequest should use when creat开发者_如何学Pythoning a connection to a remote resource? For example, I have an MVC 2 website which runs on IP 0.0.0.10
, but the server has 0.0.0.1 - 0.0.0.10
assigned to it. In the website there is a class that will be initialized based on user input and it will create requests to remote resources.
The problem I'm having is that the WebRequest is most likely using 0.0.0.1
as it is the first IP of the server instead of the IP of the website, thus causing requests to be blocked from remote resources that filter by IPs...
So, is there a way to specify the IP the WebRequest should use when performing the request. Alternativelly, it doesn't have to be a solution for WebRequest, it can be a solution for HttpWebRequest, or if need be something else. If I have to I will alter the code for the requests/responses.
Anyway, help would be much appreciated! Thanks in advance!
I think you want to use the HttpWebRequest.ServicePoint to specify a particular IP address to use for the request. See the MSDN doc, or better yet, Malar Chinnusamy's blog post that seems to be doing exactly what you're looking for.
What you want to do is IP address spoofing - http://en.wikipedia.org/wiki/IP_address_spoofing.
You could make that filter consider the address range as valid. Is that an option?
精彩评论