https 出现host name not match 问题

来源:互联网 发布:erp软件开发 编辑:程序博客网 时间:2024/06/06 10:04

'www.xxx.com' does not match the certificate subject provided by the peer

出现这个问题的原因是你访问的域名和你访问服务器的证书的机构(域名)不一致导致的,比如,你的证书是为域名 sss.com注册的,而你访问的时候的域名是xxx.com,这个时候就会报这种错误,解决办法是重写httpclient的HostnameVerifier,如下:


SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(context, new String[] { "TLSv1.2"},null, new HostnameVerifier(){@Overridepublic boolean verify(String hostname, SSLSession session) {hostname = "*.sss.com";return SSLConnectionSocketFactory.getDefaultHostnameVerifier().verify(hostname, session);}});


0 0