从Android服务尝试httprequest时,Android M中的连接被拒绝

时间:2017-01-13 05:41:52

标签: android android-studio

IOException
01-11 18:28:25.304 W/System.err: org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.1.42 refused
01-11 18:28:25.306 W/System.err:     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:193)
01-11 18:28:25.306 W/System.err:     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:169)
01-11 18:28:25.306 W/System.err:     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:124)
01-11 18:28:25.306 W/System.err:     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:370)
01-11 18:28:25.306 W/System.err:     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:560)
01-11 18:28:25.306 W/System.err:     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:492)
01-11 18:28:25.307 W/System.err:     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:470)
01-11 18:28:25.307 W/System.err:     at com.aceuat.sms.ACESMSGService.connectServerTeachr(ACESMSGService.java:213)
01-11 18:28:25.307 W/System.err:     at com.aceuat.sms.ACESMSGService$1$1.run(ACESMSGService.java:103)
01-11 18:28:25.307 W/System.err:     at java.lang.Thread.run(Thread.java:818)
01-11 18:28:25.307 W/System.err: Caused by: java.net.ConnectException: socket failed: EACCES (Permission denied)
01-11 18:28:25.307 W/System.err:     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:190)
01-11 18:28:25.307 W/System.err:    ... 9 more
01-11 18:28:25.307 W/System.err: Caused by: java.net.SocketException: socket failed: EACCES (Permission denied)
01-11 18:28:25.313 W/System.err:     at libcore.io.IoBridge.socket(IoBridge.java:619)
01-11 18:28:25.313 W/System.err:     at java.net.PlainSocketImpl.create(PlainSocketImpl.java:198)
01-11 18:28:25.314 W/System.err:     at java.net.Socket.checkOpenAndCreate(Socket.java:689)
01-11 18:28:25.314 W/System.err:     at java.net.Socket.connect(Socket.java:849)
01-11 18:28:25.314 W/System.err:     at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:124)
01-11 18:28:25.314 W/System.err:     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:149)
01-11 18:28:25.314 W/System.err:    ... 9 more
01-11 18:28:25.314 W/System.err: Caused by: android.system.ErrnoException: socket failed: EACCES (Permission denied)
01-11 18:28:25.314 W/System.err:     at libcore.io.Posix.socket(Native Method)
01-11 18:28:25.314 W/System.err:     at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:282)
01-11 18:28:25.314 W/System.err:     at libcore.io.IoBridge.socket(IoBridge.java:604)
01-11 18:28:25.314 W/System.err:    ... 14 more
01-11 18:28:40.280 I/ACES: Service is still running

它在Android较低版本中运行良好。

1 个答案:

答案 0 :(得分:1)

问题显示:您需要在应用中添加互联网访问权限。

<manifest xlmns:android...>
 ...
   <uses-permission android:name="android.permission.INTERNET" />
   <application ...
 </manifest>

最后当应用程序在弹出窗口中要求访问互联网时,允许该应用使用互联网!