Ksoap2 2.5.4和HttpsTransportSE vs AndroidHttpTransport

时间:2011-05-04 13:34:31

标签: android ksoap2

这很好但是AndroidHttpTransport已被弃用:

AndroidHttpTransport t = new AndroidHttpTransport("http://a.com/service.asmx");
t.call(action, envelope);

这会产生SSLProtocolException(但我不想使用SSL):

HttpsTransportSE t = new HttpsTransportSE("a.com", 80, "/service.asmx", timeout);
t.call(action, envelope);

3 个答案:

答案 0 :(得分:5)

HttpTransportSE(String url)应该可以工作。

答案 1 :(得分:0)

fhucho :HttpTransportSE(String url)相同的问题不在2.5.4中, 有HttpTransportSE(host,port,filaname,timeout)

答案 2 :(得分:0)

这段代码对我有用,也适合你:

String webServiceResponse = null;         SoapObject result = null;

    String url ="http://a.com/service.asmx";

    String soapaction = namespace + method;
    SoapObject request_login = new SoapObject(namespace, method);
    request.addProperty(<field_name>, <value>);


    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);

    try {
        AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(
                url);
        androidHttpTransport.call(soapaction, envelope);
        if (envelope.bodyIn instanceof SoapFault) {
            String str = ((SoapFault) envelope.bodyIn).faultstring;
            Log.i("", str);
            webServiceResponse = null;
        } else {
            result_login_String = (SoapObject) envelope.bodyIn;
            webServiceResponse = result.getProperty(0)
                    .toString();
        }
    } catch (Exception e) {
        webServiceResponse = null;
    }