Networking code sometimes throws UnknownHostException

前端 未结 4 863
迷失自我
迷失自我 2020-11-29 13:30

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?

4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 13:51

    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.

提交回复
热议问题