无法解析主机:没有与主机名关联的地址
在我的 Android 应用程序中,我使用通过 cloudflare 网络(带有主动代理)交付的 Rest API。很多时候,第一次连接 okhttp API 时会收到以下错误:
Non-fatal Exception: java.net.UnknownHostException
Unable to resolve host "mydomain.com": No address associated with hostname
用户重试一次或多次后,后续连接会成功。如果 API 请求出现一些停机时间,则该错误可能会再次发生。
我不明白是什么原因导致了这个问题。是否可以依赖cloudflare或者okhttp方面是否有办法解决。
你有什么想法吗?
In my Android application I use my Rest API, delivered via the cloudflare network (with active proxy). Very often the first connection to the okhttp API receives the following error:
Non-fatal Exception: java.net.UnknownHostException
Unable to resolve host "mydomain.com": No address associated with hostname
After the user retries one or more times, subsequent connections are successful. If there is some downtime with API requests, the error is likely to occur again.
I cannot understand what causes this problem. If it can depend on cloudflare or if there is a way to solve on the okhttp side.
do you have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
或者您的设备上没有互联网
,或者您忘记在manifest.xml中添加
权限
@see 此线程
Or you have no internet on the device
or you forgot to add
permission in manifest.xml
@see this thread
我的一个加密钱包也遇到了同样的问题,只是发现我的应用程序需要更新,一旦我更新了应用程序,从那时起一切就都很顺利了。当我第一次去 Play 商店查看是否有任何更新时,没有任何更新,但当我在 Play 商店中专门搜索我的钱包应用程序时,需要更新。因此,请确保您在 Play 商店中搜索出现问题的特定应用程序。
I had the same problem with one of my crypto wallets only to discover my app needed to be updated and once I updated the app everything was smooth from that point on. When I first went to the Play Store to see if I had any updates due, there were none but when I searched specifically for my wallet app in the Play store an update was needed. So make sure you search for the specific app that is giving you the problem in the Play store.
我也有同样的问题,但重新启动 android studio 后它解决了我的问题。
I have also the same issue but after restarting android studio it solved my problem.