您的位置:首页 > 理论基础 > 计算机网络

android ksoap2 访问https javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorExce

2016-08-26 14:27 881 查看
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<String, String> params) {

// 指定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 SoapSerializa
4000
tionEnvelope(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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐