tags:

views:

826

answers:

3

Is it possible (and if yes, how) to bypass DNS when doing a HTTP request ?

I want to hit directly a front-end with an HTTP request, without getting through NLB but with the correct host header. As I have the IP of my server, I just need to bypass the DNS.

I tried to use WebRequest, replacing the URL with the IP and setting the Host header, but this header is protected.

How can I do that ? Do I need to create the HTTP request myself ?

Note: editing host file is not an option

+2  A: 

I've done some searching and all I've been able to establish is that you are not the only person with this problem. I think the comment at the end of the MSDN article for HttpWebRequest.Headers says it all. You should vote for the entry at Microsoft Connect http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=384456

I don't know if this is possible for you, but one way around your problem may be to give each of your web sites a different port number and then access them that way or you could even give each of your load balanced servers there own DNS entry. I don't know about other web server's, but I know IIS can have more than one host header entry set up for each web site.

Failing the above, I think the only option left is to open the TCP/IP Socket directly and do the whole HTTP request yourself or use some other 3rd Party library.

Martin Brown
A: 

I have a similar problem myself, but managed to get around it using sockets (As mentioned by Martin Brown. Here is my answer: http://stackoverflow.com/questions/359041/request-web-page-in-c-spoofing-the-host#359299

Xetius
However, in my case I want Kerberos authentication and I'll need 302 redirection. It don't really feel recoding all that stuff :)
Nico
A: 

I manage to do what I need setting the proxy to the IP address of the remote server :

request.Proxy = new WebProxy(ip.ToString());

It doesn't work in all scenarios, but it did in my case.

Nico