网络代码有时会抛出 UnknownHostException [英] Networking code sometimes throws UnknownHostException

查看:29
本文介绍了网络代码有时会抛出 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 服务器出现故障,可能会发生这种情况.除了使 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屋!

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