联网代码有时会抛出UnknownHostException [英] Networking code sometimes throws UnknownHostException
问题描述
我正在尝试从服务器中获取数据.有时我的代码由于UnknownHostException
而失败.这是为什么?是什么原因造成的?
I am trying to data from a server. Sometimes my code fails due to an UnknownHostException
. Why is that? What is the cause of this problem?
推荐答案
如果DNS服务器出现打h,则可能会发生这种情况.除了使DNS服务器更强大或寻找另一台服务器之外,您还可以使用完整的IP地址代替主机名.这样,就无需根据主机名查找IP地址.但是,我宁愿解决DNS问题,而宁愿使用DNS,因为IP地址可能会不时更改.
This may occur if a hiccup in DNS server has occurred. Apart from making the DNS server more robust or looking for another one, you can also just use the full IP address instead of the hostname. This way it doesn't need to lookup the IP address based on the hostname. However, I would rather fix the DNS issue and prefer the DNS since IP addresses may change from time to time.
这篇关于联网代码有时会抛出UnknownHostException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!