3

我正在使用 kSoap2 访问肥皂网络服务。我在执行以下行时收到java.net.connectException

androidHttpTransport.call(Constants.SOAP_ACTION_GET_METHOD_NAME, envelope)   

这并不总是发生,但有时会发生。这是与服务器连接超时的问题吗?如何增加 kSoap 中的连接超时?我用谷歌搜索,但找不到解决方案。谁能建议我解决此错误的解决方案。

Logcat 详细信息如下:

07-17 14:46:24.800: W/System.err(8103): java.net.ConnectException: failed to connect to www.yahoo.com/175.41.138.237 (port 80) after 20000ms: isConnected failed: ENETUNREACH (Network is unreachable)
07-17 14:46:24.800: W/System.err(8103):     at libcore.io.IoBridge.isConnected(IoBridge.java:214)
07-17 14:46:24.800: W/System.err(8103):     at libcore.io.IoBridge.connectErrno(IoBridge.java:152)
07-17 14:46:24.800: W/System.err(8103):     at libcore.io.IoBridge.connect(IoBridge.java:112)
07-17 14:46:24.800: W/System.err(8103):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
07-17 14:46:24.800: W/System.err(8103):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
07-17 14:46:24.800: W/System.err(8103):     at java.net.Socket.connect(Socket.java:842)
07-17 14:46:24.800: W/System.err(8103):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:77)
07-17 14:46:24.800: W/System.err(8103):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
07-17 14:46:24.800: W/System.err(8103):     at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
07-17 14:46:24.800: W/System.err(8103):     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
07-17 14:46:24.810: W/System.err(8103):     at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
07-17 14:46:24.810: W/System.err(8103):     at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
07-17 14:46:24.810: W/System.err(8103):     at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
07-17 14:46:24.810: W/System.err(8103):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
07-17 14:46:24.810: W/System.err(8103):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
07-17 14:46:24.810: W/System.err(8103):     at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
07-17 14:46:24.810: W/System.err(8103):     at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:80)
4

1 回答 1

1

如何增加 kSoap 中的连接超时?

HttpTransportSE在某些情况下,忽略超时值似乎仍然存在一个悬而未决的问题。请参阅此相关链接

但是,对此的解决方案涉及修改现有的ksoap2 API.

感谢Lightsoftai的开发人员,您现在可以HttpTransportSE使用以下代码添加超时:

注意您可以为此使用 ksoap2 API 版本 2.5.2 或更高版本

       /**
       * Creates instance of HttpTransportSE with set url
       *
       * @param url 
       *             the destination to POST SOAP data
       */
         public HttpTransportSE(String url) {
         super(url);
         }

       /**
      * Creates instance of HttpTransportSE with set url
      *
      * @param url
      *            the destination to POST SOAP data
      * @param timeout
      *               timeout for connection and Read Timeouts (milliseconds)
       */
       public HttpTransportSE(String url, int timeout) {
       super(url, timeout);
          }

您可以从此处下载相同的 jar 文件。

另请参阅ksoap never timeout

希望能帮助到你。

于 2012-07-19T08:04:59.840 回答