操作超时

时间:2012-09-06 04:01:19

标签: android web-services timeout httpresponse socketexception

我有这个奇怪的错误:我甚至试图解决它的无限超时。我说这很奇怪,因为它曾经工作得很好,但现在,它不起作用,我不知道原因。错误:

09-05 22:40:04.930: W/IInputConnectionWrapper(820): showStatusIcon on inactive InputConnection
09-05 22:43:26.901: E/ServicioRest(881): Error en listar!
09-05 22:43:26.901: E/ServicioRest(881): java.net.SocketException: The operation timed out
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocketImpl(Native Method)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.harmony.luni.platform.OSNetworkSystem.connect(OSNetworkSystem.java:115)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:244)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:533)
09-05 22:43:26.901: E/ServicioRest(881):    at java.net.Socket.connect(Socket.java:1055)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
09-05 22:43:26.901: E/ServicioRest(881):    at com.example.interviewhelpers.ClientDetailActivity.onCreateView(ClientDetailActivity.java:72)
09-05 22:43:26.901: E/ServicioRest(881):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
09-05 22:43:26.901: E/ServicioRest(881):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
09-05 22:43:26.901: E/ServicioRest(881):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
09-05 22:43:26.901: E/ServicioRest(881):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
09-05 22:43:26.901: E/ServicioRest(881):    at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:505)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.Activity.performStart(Activity.java:3781)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2636)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-05 22:43:26.901: E/ServicioRest(881):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-05 22:43:26.901: E/ServicioRest(881):    at android.os.Looper.loop(Looper.java:123)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.ActivityThread.main(ActivityThread.java:4627)
09-05 22:43:26.901: E/ServicioRest(881):    at java.lang.reflect.Method.invokeNative(Native Method)
09-05 22:43:26.901: E/ServicioRest(881):    at java.lang.reflect.Method.invoke(Method.java:521)
09-05 22:43:26.901: E/ServicioRest(881):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-05 22:43:26.901: E/ServicioRest(881):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-05 22:43:26.901: E/ServicioRest(881):    at dalvik.system.NativeStart.main(Native Method)

这是调用Web服务的方法:最后一行是eclipse告诉我发生问题的地方。

public static final String ruta = "http://10.0.0.2:2731/Api/Usuario";

        HttpParams httpParameters = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParameters, 0);
        HttpConnectionParams.setSoTimeout(httpParameters, 0);
        HttpConnectionParams.setTcpNoDelay(httpParameters, true);

        HttpClient httpClient = new DefaultHttpClient(httpParameters);
        HttpGet del = new HttpGet(ruta + "s");
        del.setHeader("content-type", "application/json");

        try {
            HttpResponse resp = httpClient.execute(del);

1 个答案:

答案 0 :(得分:1)

您在代码中将超时值设为0。而不是0,您使用大于5000(毫秒)的值。      即HttpConnectionParams.setConnectionTimeout(httpParameters,5000);         HttpConnectionParams.setSoTimeout(httpParameters,5000);