第一行代碼使用網(wǎng)絡(luò)技術(shù)這一章囤耳,解析XML格式數(shù)據(jù),要求訪問(wèn)主機(jī)Apache服務(wù)器下的xml文件
書里的代碼是用10.0.2.2來(lái)表示電腦本機(jī)的IP地址偶芍,但似乎只適用于AS的模擬器紫皇,我用真機(jī)測(cè)試的時(shí)候就出現(xiàn)錯(cuò)誤:
03-12 19:23:44.089 16677-16796/cn.jnu.networktest W/System.err: java.net.SocketTimeoutException: failed to connect to /10.0.2.2 (port 80) from /192.168.0.101 (port 42744) after 10000ms
03-12 19:23:44.092 16677-16796/cn.jnu.networktest W/System.err: at libcore.io.IoBridge.connectErrno(IoBridge.java:185)
03-12 19:23:44.092 16677-16796/cn.jnu.networktest W/System.err: at libcore.io.IoBridge.connect(IoBridge.java:129)
03-12 19:23:44.093 16677-16796/cn.jnu.networktest W/System.err: at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:137)
03-12 19:23:44.093 16677-16796/cn.jnu.networktest W/System.err: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:390)
03-12 19:23:44.094 16677-16796/cn.jnu.networktest W/System.err: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
03-12 19:23:44.094 16677-16796/cn.jnu.networktest W/System.err: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
03-12 19:23:44.095 16677-16796/cn.jnu.networktest W/System.err: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
03-12 19:23:44.095 16677-16796/cn.jnu.networktest W/System.err: at java.net.Socket.connect(Socket.java:621)
03-12 19:23:44.095 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.internal.platform.AndroidPlatform.connectSocket(AndroidPlatform.java:61)
03-12 19:23:44.096 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:187)
03-12 19:23:44.096 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.internal.connection.RealConnection.buildConnection(RealConnection.java:173)
03-12 19:23:44.097 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:114)
03-12 19:23:44.097 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:193)
03-12 19:23:44.098 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:129)
03-12 19:23:44.098 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:98)
03-12 19:23:44.099 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
03-12 19:23:44.099 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
03-12 19:23:44.100 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
03-12 19:23:44.100 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:109)
03-12 19:23:44.102 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
03-12 19:23:44.103 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
03-12 19:23:44.103 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
03-12 19:23:44.104 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
03-12 19:23:44.104 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:124)
03-12 19:23:44.104 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
03-12 19:23:44.105 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
03-12 19:23:44.105 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170)
03-12 19:23:44.105 16677-16796/cn.jnu.networktest W/System.err: at okhttp3.RealCall.execute(RealCall.java:60)
03-12 19:23:44.106 16677-16796/cn.jnu.networktest W/System.err: at cn.jnu.networktest.MainActivity$2.run(MainActivity.java:102)
03-12 19:23:44.106 16677-16796/cn.jnu.networktest W/System.err: at java.lang.Thread.run(Thread.java:764)
因?yàn)槲业氖謾C(jī)跟電腦連的是同一個(gè)路由,我試圖用主機(jī)的局域網(wǎng)地址來(lái)連接腋寨,發(fā)現(xiàn)還是不行聪铺。我還試圖給它加上監(jiān)聽(tīng)的80端口,然并卵萄窜。
然后我是著把該死的防火墻給它關(guān)了铃剔,就哦了。