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;
}
解决方案:
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;
}
相关文章推荐
- andorid HTTPS 不需要证书 VolleyEror: com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not fou
- javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException:
- 调用https接口抛出javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path
- javax.net.ssl.SSLHandshakeException: com.android.org.bouncycastle.jce.exception.ExtCertPathValidator
- 【cas、tomcat】HTTP Status 500 - javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateExc
- javax.net.ssl.SSLHandshakeException: org.bouncycastle.jce.exception.ExtCertPathValidatorException: I
- Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path
- javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed
- android 访问https 证书问题 报错javax.net.ssl.SSLHandshakeException
- 解决 javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path buildin
- javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building f
- javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building
- Linux下tomcat配置ssl中报错问题的解决javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateExcepti
- 使用Java访问https接口javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
- javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building f
- javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building
- javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException: PKIX path building失败
- 【转载】javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted c
- 爬数据出现错误javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException
- 访问https,抛出的异常javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure