Http 请求 - 绕过 DNS [.Net]
在执行 HTTP 请求时是否可以(如果可以,如何)绕过 DNS?
我想使用 HTTP 请求直接访问前端,而不通过 NLB,但使用正确的主机标头。 由于我有服务器的 IP,因此我只需要绕过 DNS。
我尝试使用 WebRequest,用 IP 替换 URL 并设置 Host 标头,但该标头受到保护。
我怎样才能做到这一点 ? 我需要自己创建 HTTP 请求吗?
注意:编辑主机文件不是一个选项
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在提出这个问题时,WebRequest 类无法做到这一点。 然而,在因该问题引发 Microsoft Connect 问题后,Microsoft 将 Host 属性添加到 .Net 4.0 版中的 HttpWebRequest 类中。 因此,如果您使用 .net 4.0 或更高版本,您可以使用此代码实现您想要的效果。
在 .Net 版本 4 之前,唯一真正的选择是打开 Socket 并自己执行 HTTP 请求,或者找到具有更多功能的第 3 方组件。
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.
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.
我设法完成我需要的设置,将代理设置为远程服务器的 IP 地址:
它并非在所有情况下都有效,但在我的情况下却有效。
I manage to do what I need setting the proxy to the IP address of the remote server :
It doesn't work in all scenarios, but it did in my case.
我自己也遇到了类似的问题,但设法使用套接字解决了这个问题(正如马丁·布朗所提到的。这是我的答案:https://stackoverflow.com/questions/359041/request-web-page-in-c-spoofing-the-host#359299
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
您可以使用我的解决方案来解决此问题,它发布在这里:
如何在 HttpWebRequest 中设置自定义“主机”标头?
这可以帮助您编辑主机标头,并避免使用代理解决方法。
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.