In order to perform automated post-deployement tests on each web server behind a load balancing system, I would like to change to which ip address my request will be sent, but using the same domain name.
For example, "www.mydomain.com" normally resolves to a public address associated to the internal address 10.0.0.80 which is the load balancer address.
I would like to perform the same test on the 4 web servers behind it, so I would need "www.mydomain.com" to resolve to 10.0.0.81 for the first test, 10.0.0.82 for the second, etc.
What I would like to do is the equivalent of changing the Windows "hosts" file, but programmatically for a specific request, is this something possible ?
I don't think so. But the IP Address doesn't actually appear in an HTTP request. It only controls where the socket is opened before the request is sent. By default you use a hostname for two different purposes in an HTTP library. The host is resolved to an IP to open the socket, and it's also copied to the host header so a web server can route among multiple sites hosted on the same port.
Using HttpWebRequest (or sockets of course) you can send the same HTTP request to a different IP address. Just replace the hostname in the Uri with the IP address, and explicitly write the host header.
Something like: