Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Http Request - Bypass DNS [.Net]

Tags:

.net

http

dns

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

like image 301
Nico Avatar asked Nov 27 '08 08:11

Nico


2 Answers

At the time this question was asked this was not possible to do with the WebRequest class. However following a Microsoft Connect issue raised as a result of this question, Microsoft Added the Host property to the HttpWebRequest class in .Net version 4.0. As such if you are using .net 4.0 or later you can achieve what you want with this code.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://127.0.0.1");
Request.Host = "www.example.com"

Prior to version 4 of .Net the only real option is to open a Socket and do the HTTP request yourself or find a 3rd Party component that has more functionality.

like image 76
Martin Brown Avatar answered Nov 16 '22 15:11

Martin Brown


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.

like image 3
Nico Avatar answered Nov 16 '22 15:11

Nico