views:

158

answers:

2

Hey,

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.

A: 

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.

Jeremy McGee
Thanks... This was so long ago that I forget the actual workaround we finished with but I believe this was actually how we did it. I think webproxy takes an IP:port rather than http protocol though. I'll mark this right though so that if anyone else is looking they can find it (Forgot to put up answer when I found a solution originally).
Tim Schneider
No worries. Found this question on a drive-by search... ;-)
Jeremy McGee
A: 

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.
Akash Kava
You appear to have completely misunderstood the question, changing the configuration will not help in any way because both webservers expect the same HOST header requested off them but it only resolves to one of them. So it's not x.com and y.com, they're both x.com.
Tim Schneider
I know, but when we deploy different web servers with different host header as well according to configuration that we need, anyway I think Jeremy's answer suites you thats good.
Akash Kava