0

我正在开发一个 android 应用程序并调用 REST Web 服务。它给出了一个错误
这是我的日志

05-31 12:23:34.355: W/System.err(766): org.apache.http.conn.HttpHostConnectException: Connection to http://myip:8084 refused  
05-31 12:23:34.365: W/System.err(766): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)  
05-31 12:23:34.365: W/System.err(766):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
05-31 12:23:34.365: W/System.err(766):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
05-31 12:23:34.365: W/System.err(766):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
05-31 12:23:34.375: W/System.err(766):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)  
05-31 12:23:34.375: W/System.err(766):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-31 12:23:34.375: W/System.err(766):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
05-31 12:23:34.375: W/System.err(766):  at com.example.locationtracker.RestWSUser.sendThroughHttpGet(RestWSUser.java:38)
05-31 12:23:34.375: W/System.err(766):  at com.example.locationtracker.MainActivity.checkIn(MainActivity.java:38)
05-31 12:23:34.375: W/System.err(766):  at java.lang.reflect.Method.invokeNative(Native Method)
05-31 12:23:34.375: W/System.err(766):  at java.lang.reflect.Method.invoke(Method.java:511)
05-31 12:23:34.385: W/System.err(766):  at android.view.View$1.onClick(View.java:3594)
05-31 12:23:34.385: W/System.err(766):  at android.view.View.performClick(View.java:4204)
05-31 12:23:34.385: W/System.err(766):  at android.view.View$PerformClick.run(View.java:17355)
05-31 12:23:34.395: W/System.err(766):  at android.os.Handler.handleCallback(Handler.java:725)
05-31 12:23:34.395: W/System.err(766):  at android.os.Handler.dispatchMessage(Handler.java:92)
05-31 12:23:34.395: W/System.err(766):  at android.os.Looper.loop(Looper.java:137)
05-31 12:23:34.395: W/System.err(766):  at android.app.ActivityThread.main(ActivityThread.java:5041)
05-31 12:23:34.395: W/System.err(766):  at java.lang.reflect.Method.invokeNative(Native Method)
05-31 12:23:34.395: W/System.err(766):  at java.lang.reflect.Method.invoke(Method.java:511)
05-31 12:23:34.395: W/System.err(766):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-31 12:23:34.405: W/System.err(766):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-31 12:23:34.405: W/System.err(766):  at dalvik.system.NativeStart.main(Native Method)
05-31 12:23:34.405: W/System.err(766): Caused by: java.net.ConnectException: socket failed: EACCES (Permission denied)
05-31 12:23:34.415: W/System.err(766):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:181)
05-31 12:23:34.415: W/System.err(766):  ... 22 more
05-31 12:23:34.415: W/System.err(766): Caused by: java.net.SocketException: socket failed: EACCES (Permission denied)
05-31 12:23:34.435: W/System.err(766):  at libcore.io.IoBridge.socket(IoBridge.java:583)
05-31 12:23:34.435: W/System.err(766):  at java.net.PlainSocketImpl.create(PlainSocketImpl.java:201)
05-31 12:23:34.435: W/System.err(766):  at java.net.Socket.checkOpenAndCreate(Socket.java:663)
05-31 12:23:34.445: W/System.err(766):  at java.net.Socket.connect(Socket.java:807)
05-31 12:23:34.445: W/System.err(766):  at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
05-31 12:23:34.445: W/System.err(766):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
05-31 12:23:34.445: W/System.err(766):  ... 22 more
05-31 12:23:34.455: W/System.err(766): Caused by: libcore.io.ErrnoException: socket failed: EACCES (Permission denied)
05-31 12:23:34.465: W/System.err(766):  at libcore.io.Posix.socket(Native Method)
05-31 12:23:34.465: W/System.err(766):  at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:181)

这是我的java代码

HttpGet httpGet = new HttpGet("http://myip:8084/rest/loc/test/7225");
    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setStaleCheckingEnabled(params, false);
    HttpConnectionParams.setConnectionTimeout(params, 30000);
    HttpConnectionParams.setSoTimeout(params, 30000);
    HttpClient httpClient = new DefaultHttpClient(params);
    HttpResponse httpResponse = httpClient.execute(httpGet);
    InputStream inputStream = httpResponse.getEntity().getContent();
    BufferedReader bufferedReader = new BufferedReader(
            new InputStreamReader(inputStream));
    StringBuilder responseStr = new StringBuilder();
    String responseLineStr = null;
    while ((responseLineStr = bufferedReader.readLine()) != null) {
        responseStr.append(responseLineStr);
    } 

这是我的清单文件权限列表

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<user-permission android:name="android.permission.INTERNET"/>
<user-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

这可能是什么原因,服务正常
谢谢

4

2 回答 2

1

与其为模拟器提供myip,不如给10.0.2.2. 那应该行得通。

于 2013-05-31T23:56:29.273 回答
1

我解决了这个问题,这是一个权限问题,它真的很像一个语法问题,你们都可以在我的第一篇文章中看到它,在 Manifest 文件中

<user-permission android:name="android.permission.INTERNET"/>  

错了,应该是

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

感谢所有回复,并为我的错误感到抱歉

于 2013-06-03T08:55:23.187 回答