程序运行时 Dns 设置发生更改
我有一个使用 WebRequest 访问 http 站点的程序。 如果我启动程序执行一些 webRequests,然后更改我的计算机的 Dns 设置,该程序将不会更改 dns-servers,
例如
WebRequest.Create("http://www.google.com");
...将我的网络接口的 Dns 设置更改为无效或捕获门户...
WebRequest.Create("http://www.google.com");
// Still uses original dns server for dns lookup (or cache)
ipconfiglushdns
没有什么区别 有
什么方法可以强制 WebRequest 使用实际的 dns 服务器进行 dns 查找吗?
编辑:似乎重新启动 DnsClient 缓存的 Windows 服务就可以解决问题。虽然相当硬核
I have a program which uses WebRequest for accessing http sites.
If I start the program perform some webRequests and then change the Dns settings of my machine, the program will not change dns-servers
Like
WebRequest.Create("http://www.google.com");
....Change Dns settings for my network interface to something invalid or capturing portal....
WebRequest.Create("http://www.google.com");
// Still uses original dns server for dns lookup (or cache)
ipconfig flushdns
makes no difference
Any way I can force the WebRequest to use the actual dns server for dns lookups?
EDIT: It seems that a restart of the windows service for DnsClient cache does the trick. Quite hardcore though
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在内部,每个服务器都由 ServicePoint 类抽象。因此,一旦创建了 ServicePoint,无论是显式的还是隐式的,它都不会改变。
此外,它可能会缓存先前的连接并将其用于后续请求。
您可以尝试设置
和
看看这是否会强制 .NET 每次都创建一个新连接。
如果这不起作用,请尝试实现 BindIPEndPointDelegate() 方法并将其附加到 Web 请求。然后,对于每个请求,.NET 将调用该委托来解析端点 IPAddress,并且您可以在该委托中执行 DNS.Resolve()。
Internally, every server is abstracted by a ServicePoint class. So, once you have created a ServicePoint, either explicitly, or implicitly, it does not change.
Also, it might be caching the previous connection and using it for the subsequent request.
You can try setting
and
and see if that forces .NET to create a new connection every time.
If that doesnt work, try implementing a BindIPEndPointDelegate() method and attaching it to the webrequest. Then, for each request, .NET will call that delegate to resolve the endpoint IPAddress, and you can do a DNS.Resolve() in that delegate.