Http 请求 - 绕过 DNS [.Net]

发布于 2024-07-09 15:32:22 字数 249 浏览 3 评论 0原文

在执行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

も星光 2024-07-16 15:32:22

在提出这个问题时,WebRequest 类无法做到这一点。 然而,在因该问题引发 Microsoft Connect 问题后,Microsoft 将 Host 属性添加到 .Net 4.0 版中的 HttpWebRequest 类中。 因此,如果您使用 .net 4.0 或更高版本,您可以使用此代码实现您想要的效果。

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

在 .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.

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.

此岸叶落 2024-07-16 15:32:22

我设法完成我需要的设置,将代理设置为远程服务器的 IP 地址:

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

它并非在所有情况下都有效,但在我的情况下却有效。

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.

余生共白头 2024-07-16 15:32:22

我自己也遇到了类似的问题,但设法使用套接字解决了这个问题(正如马丁·布朗所提到的。这是我的答案: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

硬不硬你别怂 2024-07-16 15:32:22

您可以使用我的解决方案来解决此问题,它发布在这里:

如何在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文