11

我的 android 代码中有一个函数,它使用 KSOAP 将数据发送到 Web 服务。我可以向服务发送数据,但有时会出现异常:“系统调用期间出现 SSLException I/O 错误,连接超时”。

在进行了几次测试后,我的观察结果是:

  • 如果 wifi/移动数据已经打开并且我将数据发送到 Web 服务,我不会收到异常。
  • 只有当我打开 wifi/移动数据并在我尝试发送数据时连接它时,我才会得到它。

我对如何克服这个异常一无所知。如果你可以请建议/指导我如何克服这个例外将是一个很大的帮助。

以下是用于向 ASYNC 任务中调用的 Web 服务发送数据的方法。

public String incidentDataToServer(JSONObject incidentJSON) {
        // package the request
        SoapObject Request = new SoapObject(INCIDENT_NAMESPACE,
                INCIDENT_METHOD_NAME);
        String incidentData = incidentJSON.toString();
        PropertyInfo pi = new PropertyInfo();
        pi.setName("IncidentJSonString");
        pi.setValue(incidentData);
        pi.setType(String.class);
        Request.addProperty(pi);

        // set the soap serialization envelope, set it to .net and package
        // the entire request and pass to soap envelope.
        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        soapEnvelope.dotNet = true;
        soapEnvelope.setOutputSoapObject(Request);

        HttpTransportSE aht = new HttpTransportSE(URL);
        try {

            aht.call(INCIDENT_SOAP_ACTION, soapEnvelope);
            SoapPrimitive resultString = (SoapPrimitive) soapEnvelope
                    .getResponse();

            resIncident = resultString.toString();

        } catch (Exception e) {
            e.printStackTrace();

        }
        return resIncident;

    }

wifi上的异常

03-27 09:36:45.920: W/System.err(7603): javax.net.ssl.SSLException: Write error: ssl=0x4818f2c8: I/O error during system call, Connection timed out
03-27 09:36:45.960: W/System.err(7603):     at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_write(Native Method)
03-27 09:36:45.960: W/System.err(7603):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:693)
03-27 09:36:45.960: W/System.err(7603):     at java.io.BufferedOutputStream.flushInternal(BufferedOutputStream.java:185)
03-27 09:36:45.960: W/System.err(7603):     at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:85)
03-27 09:36:45.960: W/System.err(7603):     at libcore.net.http.FixedLengthOutputStream.flush(FixedLengthOutputStream.java:49)
03-27 09:36:45.960: W/System.err(7603):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:188)
03-27 09:36:45.960: W/System.err(7603):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
03-27 09:36:45.960: W/System.err(7603):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)
03-27 09:36:45.960: W/System.err(7603):     at com.dimensions.dimensionsapp.ServerAuthentication.incidentDataToServer(ServerAuthentication.java:121)
03-27 09:36:45.960: W/System.err(7603):     at com.dimensions.dimensionsapp.DataToServer$IncidentDataToServer.doInBackground(DataToServer.java:89)
03-27 09:36:45.960: W/System.err(7603):     at com.dimensions.dimensionsapp.DataToServer$IncidentDataToServer.doInBackground(DataToServer.java:1)
03-27 09:36:45.970: W/System.err(7603):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
03-27 09:36:45.970: W/System.err(7603):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-27 09:36:45.970: W/System.err(7603):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-27 09:36:45.970: W/System.err(7603):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
03-27 09:36:45.970: W/System.err(7603):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
03-27 09:36:45.970: W/System.err(7603):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
03-27 09:36:45.970: W/System.err(7603):     at java.lang.Thread.run(Thread.java:856)

移动数据例外

03-27 09:47:46.279: W/System.err(3795):     at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_write(Native Method)
03-27 09:47:46.279: W/System.err(3795):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:693)
03-27 09:47:46.279: W/System.err(3795):     at java.io.BufferedOutputStream.flushInternal(BufferedOutputStream.java:185)
03-27 09:47:46.279: W/System.err(3795):     at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:85)
03-27 09:47:46.299: W/System.err(3795):     at libcore.net.http.FixedLengthOutputStream.flush(FixedLengthOutputStream.java:49)
03-27 09:47:46.299: W/System.err(3795):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:188)
03-27 09:47:46.299: W/System.err(3795):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
03-27 09:47:46.309: W/System.err(3795):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)
03-27 09:47:46.319: W/System.err(3795):     at com.dimensions.dimensionsapp.ServerAuthentication.incidentDataToServer(ServerAuthentication.java:121)
03-27 09:47:46.319: W/System.err(3795):     at com.dimensions.dimensionsapp.DataToServer$IncidentDataToServer.doInBackground(DataToServer.java:89)
03-27 09:47:46.319: W/System.err(3795):     at com.dimensions.dimensionsapp.DataToServer$IncidentDataToServer.doInBackground(DataToServer.java:1)
03-27 09:47:46.319: W/System.err(3795):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
03-27 09:47:46.319: W/System.err(3795):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-27 09:47:46.339: W/System.err(3795):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-27 09:47:46.339: W/System.err(3795):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
03-27 09:47:46.339: W/System.err(3795):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
03-27 09:47:46.339: W/System.err(3795):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
03-27 09:47:46.339: W/System.err(3795):     at java.lang.Thread.run(Thread.java:856)

谢谢你。

4

2 回答 2

1

这似乎类似于 Android 中返回断开连接的错误:https ://code.google.com/p/android/issues/detail?id=65463 。

ksoap2-android 库受此影响,您的 SOAP 库也可能受此影响。引用这个问题:

如果您将 ksoap 用于 android:

ArrayList<HeaderProperty> headerPropertyArrayList = new ArrayList<HeaderProperty>();
headerPropertyArrayList.add(new HeaderProperty("Connection", "close"));

并使用 更新您的通话.call(SOAP_ACTION, envelope, headerPropertyArrayList)

于 2015-03-16T21:35:48.500 回答
0

我知道这是旧的,但只是增加了对话。

我不时在山区收到此消息,当互联网中断或太弱时,恰好在向我们的服务器发出 api 调用的 ssl 握手的那一刻。在那次通话之前,互联网可能是可用的,但在中途,互联网会在不方便的时间点掉线

如果我绝对需要调用成功,我会采取什么措施来缓解这种情况,即根据捕获的异常构建一个重试队列,并继续尝试调用,直到它成功或者你得到某种确认。

出于这个原因,我还在探索将我的 https 网络调用转移到基于 MQTT 的东西上,以减少这些握手所花费的开销。我们的应用程序在互联网很粗略的地方是关键任务,对大多数人来说可能是矫枉过正。

于 2019-12-16T01:05:22.593 回答