java.net.UnknownHostException:无法解析主机“ domain.com”:没有与主机名关联的地址

问题描述 投票:0回答:1

遇到一个问题,即使我在AndroidManifest.xml中提供了Internet许可,使用https://github.com/square/okhttp-okhttp版本-3.12.1的应用程序也无法连接到域

但是,用户可以根据他们的评论在其设备上连接到Internet并使用其他应用。

目前,我无法重现该异常,因此,如果以前曾遇到此问题的任何人都可以帮助我更好地理解。

我现在不想升级库,因为我不想引入大的变化。

Stacktrace

Caused by: java.net.UnknownHostException: Unable to resolve host "domain.com": No address associated with hostname
    at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:156)
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
    at java.net.InetAddress.getAllByName(InetAddress.java:1152)
    at okhttp3.Dns$-CC.lambda$static$0(SourceFile:39)
    at okhttp3.-$$Lambda$Dns$mTkNcZf2K4euny3_jks6Cac6Az0.lookup(Unknown Source:0)
    at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(SourceFile:185)
    at okhttp3.internal.connection.RouteSelector.nextProxy(SourceFile:149)
    at okhttp3.internal.connection.RouteSelector.next(SourceFile:84)
    at okhttp3.internal.connection.StreamAllocation.findConnection(SourceFile:214)
    at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(SourceFile:135)
    at okhttp3.internal.connection.StreamAllocation.newStream(SourceFile:114)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(SourceFile:42)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:121)
    at okhttp3.internal.cache.CacheInterceptor.intercept(SourceFile:94)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:121)
    at okhttp3.internal.http.BridgeInterceptor.intercept(SourceFile:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:147)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(SourceFile:125)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:121)
    at com.appdynamics.eumagent.runtime.a.a$a.intercept(SourceFile:108)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:121)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:121)
    at okhttp3.RealCall.getResponseWithInterceptorChain(SourceFile:264)
    at okhttp3.RealCall.execute(SourceFile:93)

Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
    at libcore.io.Linux.android_getaddrinfo(Native Method)
    at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74)
    at libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:200)
    at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74)
    at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:135)
    ... 39 more
android okhttp
1个回答
0
投票

我通常使用Retrofit(使用Okhttp作为客户端)时遇到该错误,当设备没有任何互联网连接(WIFI或移动数据)或我的服务器端点关闭时,就会发生此错误。自己尝试!但是还有其他一些因素。例如runtime request permisionsnetwork security config

希望这会有所帮助,兄弟。>>

© www.soinside.com 2019 - 2024. All rights reserved.