钉钉提示请勿通过开发者调试模式_钉钉开放平台demo调试异常问题解决:hostname in certificate didn't match...

今天研究钉钉的开放平台,结果一个demo整了半天,这帮助系统写的也很难懂。遇到两个问题:

1、首先是执行demo时报unable to find valid certification path to requested target,错误信息如下:

request url=https://oapi.dingtalk.com/gettoken?corpid=...略...&corpsecret=...略..., exception, msg=sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

只不过经研究,按网上的方式将证书导致到信任库中也没用,于是就找了段代码直接跳过

2、但是报下面这个错:

request url=https://oapi.dingtalk.com/get_jsapi_ticket?type=jsapi&access_token=2458f4d239173a12809cc94d1915d3b7,

exception, msg=hostname in certificate didn't match: != OR

具体没空研究,找到下面代码解决:

private staticCloseableHttpClient getHttpClient() {

RegistryBuilder registryBuilder = RegistryBuilder.create();

ConnectionSocketFactory plainSF= newPlainConnectionSocketFactory();

registryBuilder.register("http", plainSF);//指定信任密钥存储对象和连接套接字工厂

try{

KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType());//信任任何链接

TrustStrategy anyTrustStrategy = newTrustStrategy() {

@Overridepublic boolean isTrusted(X509Certificate[] x509Certificates, String s) throwsCertificateException {return true;

}

};

SSLContext sslContext=SSLContexts.custom().useTLS().loadTrustMaterial(trustStore, anyTrustStrategy).build();

LayeredConnectionSocketFactory sslSF= newSSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

registryBuilder.register("https", sslSF);

}catch(KeyStoreException e) {throw newRuntimeException(e);

}catch(KeyManagementException e) {throw newRuntimeException(e);

}catch(NoSuchAlgorithmException e) {throw newRuntimeException(e);

}

Registry registry =registryBuilder.build();//设置连接管理器

PoolingHttpClientConnectionManager connManager = newPoolingHttpClientConnectionManager(registry);//connManager.setDefaultConnectionConfig(connConfig);//connManager.setDefaultSocketConfig(socketConfig);//构建客户端

returnHttpClientBuilder.create().setConnectionManager(connManager).build();

}

参考:http://blog.csdn.net/shenyunsese/article/details/41075579

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值