HttpWebRequest-预先进行DNS解析 [英] HttpWebRequest - DNS Resolution in advance

查看:111
本文介绍了HttpWebRequest-预先进行DNS解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 HttpWebRequest (即使在调用async get方法时),由于DNS解析,最长可能需要15秒:

Using the HttpWebRequest (even when calling the async get method), it can take up to 15 seconds due to DNS resolution:

域名系统(DNS)查询最多可能需要15秒才能返回或超时.

A Domain Name System (DNS) query may take up to 15 seconds to return or time out.

是否可以提前进行查询,以便在提出请求时不会花时间?

Is it possible to make this query in advance, so that it wont spend time at it when making the request?

推荐答案

HttpWebRequest 中的DNS解析很可能是不可插入的.但是,您可以自己进行解析,然后重写URL以将解析后的IP用作主机名.但是,请确保设置正确的主机头,因为许多网站都需要它.另外,我相信HTTPS会更难,因为证书验证部分基于主机名.

It is very likely that the DNS resolution in HttpWebRequest is not pluggable. But you can do the resolution yourself and rewrite the URLs to use the resolved IP as the host name. Make sure to set the correct host-header, though, because many websites require it. Also, I believe HTTPS will be harder because certificate validation is based in part on the host name.

这篇关于HttpWebRequest-预先进行DNS解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆