Does rest (resttemplate) in Java – spring library support HTTPS protocol?

I tried to connect to the web server through HTTPS protocol, but the response Getbody () returns null and must return a JSON array The statuscode is 200, the header contains correct information, and only the body is null I use the standard spring resttemplate API (postforentity()) for this purpose Maybe in order to do this, I have to use some special spin API? Unfortunately, I can't find information about HTTPS support and SSL /'tls' certificates in the spring rest documentation (which is quite limited)

Solution

You can use httpcomponentsclienthttprequestfactory to configure the resttemplate, 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>

This allows resttemplate to use Apache httpcomponents httpclient under the bottom line, which absolutely supports SSL

It looks like the httpclient provided by httpcomponentsclienthttprequestfactory. It supports SSL out of the box, so there may be almost no configuration you need

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>