0

从我的 android 应用程序中,我需要调用 Web 服务来检索一些数据。为了调用该 Web 服务,我使用了一个HttpPost实体。

问题是我收到此错误:

11-18 15:57:42.807: I/ActivityThread(151): finish dispatching broadcast to com.android.server.PowerManagerService$BatteryReceiver@2ffcad08
11-18 15:57:42.807: I/ActivityThread(151): Dispatching broadcast android.intent.action.BATTERY_CHANGED to com.android.internal.policy.impl.KeyguardUpdateMonitor$3@2ff76710
11-18 15:57:42.807: I/ActivityThread(151):   mRegistered=true mCurOrdered=false
11-18 15:57:42.807: I/ActivityThread(151): finish dispatching broadcast to com.android.internal.policy.impl.KeyguardUpdateMonitor$3@2ff76710
11-18 15:57:42.807: I/ActivityThread(151): Dispatching broadcast android.intent.action.BATTERY_CHANGED to com.android.server.connectivity.Tethering$StateReceiver@3002cf58
11-18 15:57:55.207: W/System.err(2327): java.net.SocketException: Connection reset by peer
11-18 15:57:55.217: W/System.err(2327):     at org.apache.harmony.luni.platform.OSNetworkSystem.readSocketImpl(Native Method)
11-18 15:57:55.257: W/System.err(2327):     at org.apache.harmony.luni.platform.OSNetworkSystem.read(OSNetworkSystem.java:358)
11-18 15:57:55.257: W/System.err(2327):     at org.apache.harmony.luni.net.PlainSocketImpl.read(PlainSocketImpl.java:561)
11-18 15:57:55.257: W/System.err(2327):     at org.apache.harmony.luni.net.SocketInputStream.read(SocketInputStream.java:88)
11-18 15:57:55.257: W/System.err(2327):     at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
11-18 15:57:55.257: W/System.err(2327):     at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:191)
11-18 15:57:55.257: W/System.err(2327):     at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:82)
11-18 15:57:55.267: W/System.err(2327):     at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:174)
11-18 15:57:55.267: W/System.err(2327):     at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:179)
11-18 15:57:55.277: W/System.err(2327):     at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:235)
11-18 15:57:55.277: W/System.err(2327):     at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:259)
11-18 15:57:55.277: W/System.err(2327):     at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:279)
11-18 15:57:55.287: W/System.err(2327):     at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)
11-18 15:57:55.287: W/System.err(2327):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:410)
11-18 15:57:55.297: W/System.err(2327):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
11-18 15:57:55.297: W/System.err(2327):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
11-18 15:57:55.307: W/System.err(2327):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
11-18 15:57:55.307: W/System.err(2327):     at SplashScreen.sendJsonauthRegisterSession(SplashScreen.java:241)
11-18 15:57:55.317: W/System.err(2327):     at $SplashScreenTask.doInBackground(SplashScreen.java:587)
11-18 15:57:55.317: W/System.err(2327):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
11-18 15:57:55.337: I/ActivityThread(240): Dispatching broadcast android.intent.action.SERVICE_STATE to com.android.phone.PhoneApp$PhoneAppBroadcastReceiver@2fe4b590
11-18 15:57:55.337: I/ActivityThread(240):   mRegistered=true mCurOrdered=false
11-18 15:57:55.337: I/ActivityThread(240): finish dispatching broadcast to com.android.phone.PhoneApp$PhoneAppBroadcastReceiver@2fe4b590
11-18 15:57:55.347: I/ActivityThread(151): Dispatching broadcast android.intent.action.SERVICE_STATE to android.net.MobileDataStateTracker$MobileDataStateReceiver@3002b098
11-18 15:57:55.347: I/ActivityThread(247): enter process activity msg = 113
11-18 15:57:55.357: I/ActivityThread(151):   mRegistered=true mCurOrdered=false
11-18 15:57:55.357: W/System.err(2327):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-18 15:57:55.357: I/ActivityThread(151): finish dispatching broadcast to android.net.MobileDataStateTracker$MobileDataStateReceiver@3002b098
11-18 15:57:55.357: I/ActivityThread(151): Dispatching broadcast android.intent.action.ANY_DATA_STATE to android.net.MobileDataStateTracker$MobileDataStateReceiver@30023718
11-18 15:57:55.367: I/ActivityThread(151):   mRegistered=true mCurOrdered=false
11-18 15:57:55.367: I/ActivityThread(151): finish dispatching broadcast to android.net.MobileDataStateTracker$MobileDataStateReceiver@30023718
11-18 15:57:55.367: I/ActivityThread(151): Dispatching broadcast android.intent.action.ANY_DATA_STATE to android.net.MobileDataStateTracker$MobileDataStateReceiver@30023f48
11-18 15:57:55.367: I/ActivityThread(151):   mRegistered=true mCurOrdered=false
11-18 15:57:55.367: I/ActivityThread(151): finish dispatching broadcast to android.net.MobileDataStateTracker$MobileDataStateReceiver@30023f48
11-18 15:57:55.367: I/ActivityThread(151): Dispatching broadcast android.intent.action.ANY_DATA_STATE to android.net.MobileDataStateTracker$MobileDataStateReceiver@30024420
11-18 15:57:55.367: I/ActivityThread(151):   mRegistered=true mCurOrdered=false
11-18 15:57:55.367: I/ActivityThread(240): Dispatching broadcast android.intent.action.ANY_DATA_STATE to com.android.phone.PhoneApp$PhoneAppBroadcastReceiver@2fe4b590
11-18 15:57:55.367: I/ActivityThread(240):   mRegistered=true mCurOrdered=false
11-18 15:57:55.367: I/ActivityThread(240): finish dispatching broadcast to com.android.phone.PhoneApp$PhoneAppBroadcastReceiver@2fe4b590
11-18 15:57:55.377: I/ActivityThread(151): finish dispatching broadcast to android.net.MobileDataStateTracker$MobileDataStateReceiver@30024420
11-18 15:57:55.377: I/ActivityThread(151): Dispatching broadcast android.intent.action.ANY_DATA_STATE to android.net.MobileDataStateTracker$MobileDataStateReceiver@300248f8
11-18 15:57:55.377: I/ActivityThread(151):   mRegistered=true mCurOrdered=false
11-18 15:57:55.377: I/ActivityThread(151): finish dispatching broadcast to android.net.MobileDataStateTracker$MobileDataStateReceiver@300248f8
11-18 15:57:55.377: I/ActivityThread(151): Dispatching broadcast android.intent.action.ANY_DATA_STATE to android.net.MobileDataStateTracker$MobileDataStateReceiver@3002b098
11-18 15:57:55.377: I/ActivityThread(151):   mRegistered=true mCurOrdered=false
11-18 15:57:55.387: W/System.err(2327):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-18 15:57:55.387: I/ActivityThread(247): exit process activity msg = 113
11-18 15:57:55.397: W/System.err(2327):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
11-18 15:57:55.397: I/ActivityThread(151): finish dispatching broadcast to android.net.MobileDataStateTracker$MobileDataStateReceiver@3002b098
11-18 15:57:55.427: W/System.err(2327):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
11-18 15:57:55.427: W/System.err(2327):     at java.lang.Thread.run(Thread.java:1096)

错误在此行的以下方法中:

response = client.execute(post);


public boolean sendJsonauthRegisterSession(JSONObject json, String url) {

    HttpParams httpParameters = new BasicHttpParams();
    int timeoutConnection = 150000;
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); 
    int timeoutSocket = 150000;
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
    DefaultHttpClient client = new DefaultHttpClient(httpParameters);

    HttpResponse response;
    try {
        HttpPost post = new HttpPost(url);
        JSONObject js = new JSONObject();
        js.put("request_object", json);

        StringEntity se = new StringEntity(js.toString());
        se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
                "application/json"));
        post.setEntity(se);
        response = client.execute(post);

        /* Checking response */
        if (response != null) {
                    ...
        }
     } 
      catch(UnknownHostException e5){
          e5.printStackTrace();           
          this.callRegister="register_failed";
     } 
      catch(SocketException ex) {
          ex.printStackTrace();
          this.callRegister="register_failed";
     } 
      catch (Exception e) {
          e.printStackTrace();
          this.callRegister="register_failed";
     }

    client.getConnectionManager().shutdown();
    return registersession;
}

从 调用该方法AsyncTask

有人知道我做错了什么吗?谢谢!!!

重要与服务器的连接是在 3G、EDGE 上完成的......所以它非常慢。

4

1 回答 1

1

只是切断连接的服务器。

从这个问题中提取

这是相当致命的。远程服务器向您发送了一个 RST 数据包,这表明连接立即断开,而不是通常的握手。这绕过了正常的半关闭状态转换。我喜欢这样的描述:

“由对等方重置连接”是 TCP/IP 等价物,相当于将电话重新挂上。这比仅仅不回复,留下一个悬而未决更有礼貌。但这并不是真正礼貌的 TCP/IP 话务员所期望的 FIN-ACK。

于 2012-11-18T17:31:21.823 回答