ksoap timeout behind proxy in android

我们两清 提交于 2019-12-20 07:09:31

问题


i tried the example from http://www.helloandroid.com/tutorials/using-ksoap2-android-and-parsing-output-data to get request and response from a wsdl service. its working fine when i tried in a proxyless. but when i work behind proxy,i get "The operation timed out:request time failed: java.net.SocketException" is there any way to set proxy to SoapObject or Soap Envelop?


回答1:


Ksoap does not work behind a proxy. inorder to make that working.. download the HttpTransportSE.java and ServiceConnectionSE.java from sourceforge.

Create a package with HttpTransportSE and ServiceConnectionSE.

In ServiceConnectionSE constructor:

 String myProxy=android.net.Proxy.getDefaultHost() ;
            int myPort=android.net.Proxy.getDefaultPort();

            if(myProxy!=null){
                Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(myProxy, myPort));
                connection = (HttpURLConnection) new URL(url).openConnection(proxy);
            }
            else
            {
                connection = (HttpURLConnection) new URL(url).openConnection();
            }

now wherever we call HttpTransportSE.call()method make sure that it points to ur own package which has this two files.




回答2:


  Hi Everyone , The latest version of KSOAP2.6.5 [Tested it and verified it] has fix for the proxy authentication issue . The HTTPTransportSE constructor now accepts java.net.Proxy instance as a parameter along with URL. The method will be like
            HttpTransportSE httpTransport=new HttpTransportSE(proxy,URL);
  If your proxy is configured and if it requires authentication then use Authenticator class to setup your proxy credentials and have success. HTH , if not write me back




回答3:


As far as I know you have to set up the proxy in android operating system settings themselves and it will work fine.




回答4:


Replace with this..

//Timeout in milliseconds

int timeout=60000;
AndroidHttpTransport androidHttpTransport=new AndroidHttpTransport(url, timeout);


来源:https://stackoverflow.com/questions/4883896/ksoap-timeout-behind-proxy-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!