钉钉提示请勿通过开发者调试模式_钉钉开放平台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
總結
以上是生活随笔為你收集整理的钉钉提示请勿通过开发者调试模式_钉钉开放平台demo调试异常问题解决:hostname in certificate didn't match...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: access重复数据累计_Access
- 下一篇: 本地缓存需要高时效性怎么办_太难为我了,