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

发布于 2024-10-26 00:36:48 字数 174 浏览 3 评论 0原文

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

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

我怎样才能实现这个目标? KSoap2 中是否有 TimerTask 或任何超时方法?

I am using ksoap2 to create a user registration application in Android.

When I send request to the server and there is no response within 10 seconds I want to prompt the user with a "Try again" message. If the server responds within 10 seconds I want the program to proceed without the message.

How can I achieve this? Is there a TimerTask or any method for Timeout in KSoap2?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

总以为 2024-11-02 00:36:48
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 )
               {}
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 )
               {}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文