httpclient访问https
在自己的机器做了tomcat单向认证,然后用httpclient4.x访问
CloseableHttpClient client=HttpClientFactory.getCloseableHttpClient()
HttpGet get=new HttpGet("https://localhost:8443/")
// HttpGet get=new HttpGet("https://www.baidu.com")
CloseableHttpResponse response=client.execute(get)
BufferedReader reader=new BufferedReader(new InputStreamReader(response.getEntity().getContent()))
String line=reader.readLine()
while(line!=null){
log.debug(line);
line=reader.readLine()
}
访问自己的tomcat报错,SunCertPathBuilderException occurred when processing request: [GET] /cloudolp.dc/test/https
unable to find valid certification path to requested target。报错也可以理解,因为没有配置证书,但是为什么访问百度不会有问题?我也没有为百度配置证书。而且https是加密的,但我用https访问百度读到的输出流是明文,又是为什么