HttpWebRequest to different IP than the domain resolves to

Long story short an API I'm calling's different environments (dev/staging/uat/live) is set up by putting a host-record on the server so the live domain resolves to their other server in for the HTTP request.

The problem is that they've done this with so many different environments that we don't have enough servers to use the server-wide host files for it anymore (We've got some environments running off the same servers - luckily not dev and live though :P).

I'm wondering if there's a way to make WebRequest request to a domain but explicitly specify the IP of the server it should connect to? Or is there any way of doing this short of going all the way down to socket connections (Which I'd really prefer not to waste time/create bugs by trying to re-implementing the HTTP protocol).

PS: I've tried and we can't just get a new sub-domain for each environment.

Answers


One way to spoof a HTTP host header is to set a proxy to the actual server you'd like the request sent to. Something like

request.Proxy = new WebProxy(string.Format("http://{0}/", hostAddress));

may well work.


There are ways to control configuration values.

  1. You have conditional compilation enabled in .NET, in which you can create your configuration sets and create directives that can use specific domain instead of changing its resolution strategy. For example, in debug, you can use x.com and in release mode you can use y.com, wherever you need to reference your url.
  2. Web.config and app.config now supports changes as per the configuration selected, you can have web.debug.config and web.release.config and you can specify different url references here.

Need Your Help

Allowing a parameter to override other parameters in SSRS

reporting-services parameters

I'm working on a report where i need to use 4 parameters. They are SalesId, BeginningDate, Endingdate and SalesType

htaccess remove www and redirect to accessed url

php regex apache .htaccess codeigniter

I am using codeigniter framework i need to force to remove www from the url so I am using this code