博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
钉钉开放平台demo调试异常问题解决:hostname in certificate didn't match
阅读量:6127 次
发布时间:2019-06-21

本文共 2522 字,大约阅读时间需要 8 分钟。

今天研究钉钉的开放平台,结果一个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: <oapi.dingtalk.com> != <*.laiwang.com> OR <*.laiwang.com>

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

private static CloseableHttpClient getHttpClient() {        RegistryBuilder
registryBuilder = RegistryBuilder.
create(); ConnectionSocketFactory plainSF = new PlainConnectionSocketFactory(); registryBuilder.register("http", plainSF); //指定信任密钥存储对象和连接套接字工厂 try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); //信任任何链接 TrustStrategy anyTrustStrategy = new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { return true; } }; SSLContext sslContext = SSLContexts.custom().useTLS().loadTrustMaterial(trustStore, anyTrustStrategy).build(); LayeredConnectionSocketFactory sslSF = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); registryBuilder.register("https", sslSF); } catch (KeyStoreException e) { throw new RuntimeException(e); } catch (KeyManagementException e) { throw new RuntimeException(e); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } Registry
registry = registryBuilder.build(); //设置连接管理器 PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(registry);// connManager.setDefaultConnectionConfig(connConfig);// connManager.setDefaultSocketConfig(socketConfig); //构建客户端 return HttpClientBuilder.create().setConnectionManager(connManager).build(); }

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

转载于:https://www.cnblogs.com/5207/p/5254891.html

你可能感兴趣的文章
腾讯云加入LoRa联盟成为发起成员,加速推动物联网到智联网的进化
查看>>
从Python2到Python3:超百万行代码迁移实践
查看>>
Windows Server已可安装Docker,Azure开始支持Mesosphere
查看>>
简洁优雅地实现夜间模式
查看>>
react学习总结
查看>>
微软正式发布PowerShell Core 6.0
查看>>
Amazon发布新的会话管理器
查看>>
InfoQ趋势报告:DevOps 和云计算
查看>>
舍弃Python,为什么知乎选用Go重构推荐系统?
查看>>
在soapui上踩过的坑
查看>>
MySQL的字符集和字符编码笔记
查看>>
ntpd同步时间
查看>>
must implement java.io.Serializable hessian
查看>>
Microsoft Licenses Flash Lite for Windows Mobile Users
查看>>
HDOJ 2020 绝对值排序
查看>>
HDOJ/HDU 2560 Buildings(嗯~水题)
查看>>
Maven编译时跳过Test
查看>>
Spring Boot 整合Spring Security 和Swagger2 遇到的问题小结
查看>>
[20170628]12C ORA-54032.txt
查看>>
除以2
查看>>