Override IP in HTTP Request

httpresearcher picture httpresearcher · Jan 9, 2010 · Viewed 7.7k times · Source

Looking for a way to issue an HTTPwebrequest, or use the browser control, or winhttp to make a request to a URL, but override the IP address it connects to from the DNS lookup to a specific one.

Trying to do something similar to the HOSTS file, but programatically without having to modify this file. It can be C# or C+

Why I need it, the host i am sending the request has multiple IPs, and their Domain servers are doing load balancing accross the different IPs. Trying to force the request to a particular IP, but I need the host in the http request to be still the original host. I need this programatically because changing the host file every time i need to run this test is too time consuming.

Answer

Kayode Leonard picture Kayode Leonard · Dec 10, 2011

All you had to do was this:

var request = (HttpWebRequest) WebRequest.Create("http://192.168.1.1");
request.Host = "news.bbc.co.uk";