Just to share my working code for RestTemplate request with AcceptEncoding:gzip
RestTemplate restTemplate = new RestTemplate();
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setAcceptEncoding(ContentCodingType.GZIP);
HttpEntity<Coordinates> requestEntity = new HttpEntity<Coordinates>(coordinates, requestHeaders);
ResponseEntity<Integer> responseEntity = restTemplate.exchange(url, HttpMethod.PUT, requestEntity, Integer.class);
The source code in answer of @Stoozi not work for me (if you use it simple will not receive compressed response) I have test it with SoapUI
Request:
GET http://localhost:8081/jaxrs/admin-adblock
Accept:application/json
Cache-Control:no-cache
Content-Type:application/json
Authorization:Basic c21h...
Accept-Encoding:gzip,deflate
Response:
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 204
Server: Jetty(9.2.2.v20140723)
its need to use setAcceptEncoding()
instead of setContentEncoding()
in RestTemplate REQUEST headers.