gpt4 book ai didi

android - KSOAP 永不超时

转载 作者:太空宇宙 更新时间:2023-11-03 12:42:29 27 4
gpt4 key购买 nike

我正在使用支持超时的 ksoap2 2.5.4(在 Android 2.2 上)。我正在使用 Apache 2.2.16 来处理我的请求。一切正常,但当我关闭我的 Apache(或断开运行 Apache 的远程 PC)时,调用永远不会超时。我正在使用单独的线程来调用我的 WS,在这种情况下,该线程停止工作/响应/停止大约 2 分钟。

int MSG_TIMEOUT = 15000;
HttpTransportSE httpTransport;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
httpTransport = new HttpTransportSE(URL, MSG_TIMEOUT);
httpTransport.debug = true;
httpTransport.call(SOAP_ACTION, envelope);//thread stops responding here

我什至尝试在预定义的超时后使用 Timer 取消该线程,但它没有用。线程仍然存在,正在等待 2 分钟。

TimerTask task;
Timer mTimer;
task = new TimerTask() {
public void run() {
mThread.interrupt();
}
};
mTimer = new Timer();
mTimer.schedule(task, MSG_TIMEOUT);

我也收到可能与它有关的警告(我不知道该怎么办):

Dx warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.ksoap2.transport.KeepAliveHttpsTransportSE$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.

有没有机会让 KSOAP 工作或改进计时器以在预定义的超时后中断该线程?感谢您的回答或任何尝试的想法!

最佳答案

使用 ksoap2 API 版本 2.5.2 或更高版本。

您可以通过 clicking here 下载

并在创建 HTTPTransport 对象时使用以下代码。

/**
* 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);
}

关于android - KSOAP 永不超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5489671/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com