[英]Does REST (RestTemplate) in Spring Library support HTTPS protocol?
I'm trying to connect to a web server via HTTPS
, but response.getBody()
returns null
however I want to return a JSON array.我正在尝试通过HTTPS
连接到 Web 服务器,但是response.getBody()
返回null
但是我想返回一个 JSON 数组。 The statusCode
is 200 and the headers contain the correct information, but the response body is null
. statusCode
为 200 并且标头包含正确的信息,但响应正文为null
。 I'm using the standard Spring RestTemplate
API for this purpose specifically postForEntity()
.为此,我正在使用标准的 Spring RestTemplate
API,特别是postForEntity()
。 Maybe in order to do this I have to use some special Spring API?也许为了做到这一点,我必须使用一些特殊的 Spring API?
Unfortunately I couldn't find any information about HTTPS
support and SSL
/'TLS' certificates in the Spring REST documentation (it is quite limited).不幸的是,我在 Spring REST 文档中找不到任何关于HTTPS
支持和SSL
/'TLS' 证书的信息(它非常有限)。
You can configure the RestTemplate
with the HttpComponentsClientHttpRequestFactory
, for example:您可以使用HttpComponentsClientHttpRequestFactory
配置RestTemplate
,例如:
<bean id="httpComponentsClientHttpRequestFactory" class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory"/>
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<constructor-arg ref="httpComponentsClientHttpRequestFactory"/>
</bean>
That allows the RestTemplate
to use the Apache HttpComponents HttpClient under the hood, which definitely supports SSL.这允许RestTemplate
在引擎盖下使用Apache HttpComponents HttpClient ,它绝对支持 SSL。
It looks like the HttpClient
provided by HttpComponentsClientHttpRequestFactory
supports SSL out of the box, so there may be almost no configuration required on your side.看起来HttpComponentsClientHttpRequestFactory
提供的HttpClient
支持 SSL 开箱即用,因此您这边可能几乎不需要配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.