How to parse gzip encoded response with RestTemplate in Spring-Web

后端 未结 2 689
-上瘾入骨i
-上瘾入骨i 2020-12-01 11:17

After I modified Consuming a RESTful Web Service example to call get users by id from api.stackexchange.com I get JsonParseException:

com.fasterxml.jackson.cor

2条回答
  •  粉色の甜心
    2020-12-01 12:09

    Replace the default requestFactory with one from Apache HttpClient (which decodes GZIP on the fly):

    HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(
                HttpClientBuilder.create().build());
    RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory);
    

    Add Apache Http Client into pom.xml

    
        org.apache.httpcomponents
        httpclient
        
        4.5.1
    
    

提交回复
热议问题