简体   繁体   English

如何修复证书中的主机名不匹配

[英]How to fix Hostname in certificate didn't match

I'm making HTTP request to a https website using Unirest for Java, but I have problem with SSL certificate. 我正在使用Unirest for Java向HTTPS网站发出HTTP请求,但是SSL证书有问题。 Exception message - javax.net.ssl.SSLException: hostname in certificate didn't match: 异常消息-javax.net.ssl.SSLException:证书中的主机名不匹配:

Page: www.ceskereality.cz 页面:www.ceskereality.cz

If I open it in browser (I'm using Google Chrome on Windows 10), it works... 如果我在浏览器中打开它(我在Windows 10上使用的是Google Chrome),它就可以工作...

I tried this, but it isn't working 我试过了,但是没用

SSLContext sslcontext = SSLContexts.custom()
                .loadTrustMaterial(null, new TrustSelfSignedStrategy())
                .build();

SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext,SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
CloseableHttpClient httpclient = HttpClients.custom()
                .setSSLSocketFactory(sslsf)
                .build();
Unirest.setHttpClient(httpclient);

下载服务器证书并将其放在您的cacert中,然后重新启动Java应用程序。

The server requires that the client uses Server Name Indication (SNI) in order to get the correct certificate. 服务器要求客户端使用服务器名称指示(SNI)以获得正确的证书。 If no SNI is used a certificate for ci.cz instead of ceskereality.cz is returned which causes the error you see. 如果未使用SNI,则返回ci.cz而不是ceskereality.cz的证书,这将导致您看到错误。

I'm not familiar with Unirest but it is likely that the library you use does not support SNI or that you are using it with an older Java version which does not have SNI enabled. 我对Unirest不熟悉,但是您使用的库可能不支持SNI,或者您将它与未启用SNI的旧Java版本一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM