使用Apache HttpComponents HttpClient库(4.0.2)时出现问题,证书无法正确验证。该证书有效期为域名(姑且称之为example.com),但是它得到验证对IP地址而不是:Apache HttpClient将域名解析为IP地址并且没有匹配证书
主机名的证书不匹配:< 123.123.123.123> = < *! .example.com的>
我的用于使连接的代码是:
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 5000);
HttpConnectionParams.setSoTimeout(httpParams, 5000);
DefaultHttpClient httpClient = new DefaultHttpClient(httpParams);
String url = "https://www.example.com";
HttpGet get = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(get);
String response = EntityUtils.toString(httpResponse.getEntity()).trim();
通过web浏览器连接时,证书本身显示为有效和为fo有效[R我连接到域名:
CN = * .example.com的
证书也被添加到Java密钥(使用常规测试HttpsURLConnection
)。
此代码使用IP地址而不是域名的任何想法?
因此,当涉及到SSL时,域无法解析为IP。所以你不能使用IP证书来保护域名。很高兴知道。谢谢! – Rolf