在Android的Java URL中使用IP URL

时间:2016-12-11 17:07:00

标签: java android url okhttp

我正在创建一个应用程序,它与在主机笔记本电脑上运行的HTTP服务器使用REST通信。问题是我无法使用http://192.168.0.289:3000/api/poststuff的网址。我192.168.0.289的主机名查找失败。 OkHttp拒绝得到那个IP地址,并且可以绕过查找。我得到的错误是,

 W/System.err: java.net.UnknownHostException: Unable to resolve host "192.168.0.289": No address associated with hostname
 W/System.err:     at java.net.InetAddress.lookupHostByName(InetAddress.java:470)
 W/System.err:     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
 W/System.err:     at java.net.InetAddress.getAllByName(InetAddress.java:215)
 W/System.err:     at okhttp3.Dns$1.lookup(Dns.java:39)
 W/System.err:     at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:170)
 W/System.err:     at okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.java:136)
 W/System.err:     at okhttp3.internal.connection.RouteSelector.next(RouteSelector.java:81)
 W/System.err:     at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:181)
 W/System.err:     at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:132)
 W/System.err:     at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:101)
 W/System.err:     at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
 W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
 W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
 W/System.err:     at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
 W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
 W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
 W/System.err:     at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
 W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
 W/System.err:     at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
 W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
 W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
 W/System.err:     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:179)
 W/System.err:     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:129)
 W/System.err:     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
 W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
 W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
 W/System.err:     at java.lang.Thread.run(Thread.java:818)
 W/System.err: Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
 W/System.err:     at libcore.io.Posix.android_getaddrinfo(Native Method)
 W/System.err:     at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55)
 W/System.err:     at java.net.InetAddress.lookupHostByName(InetAddress.java:451)
 W/System.err:  ... 26 more

甚至不能使用HttpUrl

request = new Request.Builder()
                .url( new HttpUrl.Builder()
                        .scheme("http")
                        .host("192.168.0.289")
                        .port(3000)
                        .addPathSegment(POSTURL)
                        .build())
                .build();

成绩信息

compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.google.protobuf:protobuf-java:2.6.0'
compile 'com.squareup.okhttp3:okhttp:3.5.0'

如何使用OkHttp或其他库进行此操作?

0 个答案:

没有答案