Spring Library中的REST(RestTemplate)是否支持HTTPS协议? [英] Does REST (RestTemplate) in Spring Library support HTTPS protocol?
问题描述
我正在尝试通过 HTTPS
协议连接到网络服务器,但是 response.getBody()
返回 null
并且必须返回JSON数组。 statusCode
是200且标题包含正确的信息,只有正文 null
。为此,我使用标准的Spring RestTemplate
API( postForEntity()
)。也许为了做到这一点,我必须使用一些特殊的Sping API?
很遗憾我在Spring REST中找不到有关 HTTPS
支持和 SSL
/'TLS'证书的任何信息文档(非常有限)。
I'm trying to connect to the web server via HTTPS
protocol, but response.getBody()
returns null
and have to return a JSON array. statusCode
is 200 and headers contain correct information, only body is null
. I use standard Spring RestTemplate
API for this purpose (postForEntity()
). Maybe in order to do this I have to use some special Sping API?
Unfortunately I couldn't find any information about HTTPS
support and SSL
/'TLS' certificates in Spring REST documentation (it is quite limited).
推荐答案
您可以配置 RestTemplate
使用 HttpComponentsClientHttpRequestFactory
,例如:
You can configure the RestTemplate
with the HttpComponentsClientHttpRequestFactory
, for example:
<bean id="httpComponentsClientHttpRequestFactory" class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory"/>
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<constructor-arg ref="httpComponentsClientHttpRequestFactory"/>
</bean>
这允许 RestTemplate
使用< a href =http://hc.apache.org/httpcomponents-client-ga/httpclient/ =noreferrer>引擎盖下的Apache HttpComponents HttpClient ,它绝对支持SSL。
That allows the RestTemplate
to use the Apache HttpComponents HttpClient under the hood, which definitely supports SSL.
看起来像提供的
支持开箱即用的SSL ,因此您可能几乎不需要配置。 HttpClient
HttpComponentsClientHttpRequestFactory
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.
这篇关于Spring Library中的REST(RestTemplate)是否支持HTTPS协议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!