Http Request - Bypass DNS [.Net]

后端 未结 4 1828
生来不讨喜
生来不讨喜 2020-12-31 18:42

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 w

相关标签:
4条回答
  • 2020-12-31 19:15

    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.

    0 讨论(0)
  • 2020-12-31 19:16

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

    0 讨论(0)
  • 2020-12-31 19:26

    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.

    0 讨论(0)
  • 2020-12-31 19:27

    You can use my solution for this problem, it posted here :

    How to set custom "Host" header in HttpWebRequest?

    This can help you to edit host header, and avoid to using proxy workaround.

    0 讨论(0)
提交回复
热议问题