gpt4 book ai didi

android - 如何在android中使用kso​​ap超时?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:38:36 30 4
gpt4 key购买 nike

我正在使用 ksoap2 在 Android 中创建用户注册应用程序。

当我向服务器发送请求并且在 10 秒内没有响应时,我想用“再试一次”消息提示用户。如果服务器在 10 秒内响应,我希望程序在没有消息的情况下继续。

我怎样才能做到这一点? KSoap2 中是否有 TimerTask 或任何超时方法?

最佳答案

private String METHOD_NAME;
private String NAMESPACE;
private String SOAP_ACTION;
private String URL;
private int TimeOut=3000;//
private SoapObject so;
SoapSerializationEnvelope envelope;
HttpTransportSE androidHttpTransport;
try
{

METHOD_NAME = "myutility";
NAMESPACE = "http://";
SOAP_ACTION = NAMESPACE + METHOD_NAME;
Thread.sleep(2000);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);

URL = "http://www.example.com";
androidHttpTransport = new HttpTransportSE(URL,Time_Out);
androidHttpTransport.call(SOAP_ACTION,envelope);
so = (SoapObject)envelope.bodyIn;
String s=so.toString();
//Your processing here
}
catch(InterruptedException e)
{
//When timeout occurs handles this....

}
catch( Exception e )
{}

关于android - 如何在android中使用kso​​ap超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5400843/

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