当前位置:   article > 正文

用HttpClient发送HTTPS请求报SSLException: Certificate for <域名> doesn’t match any of the subject alternativ_certificate for <10.19.196.102> doesn't match comm

certificate for <10.19.196.102> doesn't match common name of the certificate

用exchage获取Outlook数据服务是因为证书问题导致,现在需要去除证书验证就可以访问了。

ExchangeService service = new ExchangeServiceWithHostVerify(ExchangeVersion.Exchange2010_SP2);

/**
 * 重写ExchangeService类,不对任何域名做验证
 */
private static class ExchangeServiceWithHostVerify extends ExchangeService {

    // 不对任何域名做验证
    private final static HostnameVerifier hostnameVerifierWithOutVerfy = new HostnameVerifier() {
        @Override
        public boolean verify(String s, SSLSession sslSession) {
            return true;
        }
    };

    public ExchangeServiceWithHostVerify(ExchangeVersion requestedServerVersion) {
        super(requestedServerVersion);
    }

    @Override
    protected Registry<ConnectionSocketFactory> createConnectionSocketFactoryRegistry() {
        try {
            return RegistryBuilder.<ConnectionSocketFactory>create().register(EWSConstants.HTTP_SCHEME, new PlainConnectionSocketFactory()).register(EWSConstants.HTTPS_SCHEME, EwsSSLProtocolSocketFactory.build(null, hostnameVerifierWithOutVerfy)).build();
        } catch (GeneralSecurityException e) {
            throw new RuntimeException("Could not initialize ConnectionSocketFactory instances for HttpClientConnectionManager", e);
        }
    }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/321267
推荐阅读
相关标签
  

闽ICP备14008679号