spring - RestTemplate 调用 GET HTTPS Endpoint 问题
问题描述
我尝试从浏览器调用其余端点并且工作正常,但是使用其余模板,我没有得到任何响应。
网址:https ://www1.nseindia.com/marketinfo/sym_map/symbolCount.jsp?symbol=INFY
public class Test {
public static void main(String[] args) throws Exception {
try {
String jksPath = "C:\\ssl_server.jks";
String pass = "123456";
SSLContext ssl = SSLContextBuilder.create()
.loadTrustMaterial(ResourceUtils.getFile(jksPath), pass.toCharArray()).build();
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(ssl, new LHVerifier());
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
requestFactory.setConnectionRequestTimeout(15000);
requestFactory.setReadTimeout(15000);
System.out.println("Start: " + new Date());
HttpHeaders headers = new HttpHeaders();
headers.set(org.apache.http.HttpHeaders.ACCEPT, "*/*");
HttpEntity<?> httpEntity = new HttpEntity<>(headers);
ResponseEntity<Object> response = new RestTemplate(requestFactory).exchange(
"https://www1.nseindia.com/marketinfo/sym_map/symbolCount.jsp?symbol=INFY", HttpMethod.GET,
httpEntity, Object.class);
} catch (Exception e) {
System.out.println("Exception: " + new Date());
e.printStackTrace();
}
System.out.println("done");
}
}
class LHVerifier implements HostnameVerifier {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
解决方案
推荐阅读
- arrays - 如何在 numpy 数组中找到从一个元素到下一个元素的状态转换?
- java - 如何修复 Java 中的错误源文件错误?
- r - ggplot 仅针对属于特定级别的点显示 Pareto Front
- python - 在 Jupyter Lab 中设置项目路径
- laravel - 获取关系表结果的总数
- python - 如何在 Python 中使用索引打印素数的真/假列表?
- c - for 循环内的 for 循环可以在没有大括号的情况下工作吗?
- django - 在多对多 Django 休息框架上发布
- java - java中的pkcs11 cmac计算
- react-native - ffmpeg mov 到 mp4:不够快