android 使用ksoap2 访问webservice时,若访问的是https,报https javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException
解决方案:
SsX509TrustManager.allowAllSSL();
具体如下:
public static String getWebServiceResult(String nameSpace,
String methodName, String endPoint, String soapAction,
LinkedHashMap
// 指定WebService的命名空间和调用的方法名
SoapObject rpc = new SoapObject(nameSpace, methodName);
// 设置需调用WebService接口需要传入的两个参数mobileCode、userId
for (String key : params.keySet()) {
System.out.println("Key = " + key + ", Value = " + params.get(key));
rpc.addProperty(key, params.get(key));
}
// 生成调用WebService方法的SOAP请求信息,并指定SOAP的版本
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
envelope.bodyOut = rpc;
// 设置是否调用的是dotNet开发的WebService
envelope.dotNet = false;
// 等价于envelope.bodyOut = rpc;
envelope.setOutputSoapObject(rpc);
HttpTransportSE transport = new HttpTransportSE(endPoint);
SsX509TrustManager.allowAllSSL();//关键点-------------
String result = null;
try {
// transport.debug = true;
// 调用WebService
transport.call(soapAction, envelope);
// 获取返回的数据
SoapObject object = (SoapObject) envelope.bodyIn;
// 获取返回的结果
result = object.getProperty(0).toString();
} catch (Exception e) {
// e.printStackTrace();
if (e.toString().contains("ConnectException")) {
result = "ConnectException";
}
}
return result;
}