Apache Commons HttpClient库是否支持Gzip?我们想在我们的Apache服务器上使用enable gzip压缩来加速客户端/服务器通信(我们有一个php页面,允许我们的Android应用程序与服务器同步文件).
java gzip apache-commons apache-commons-httpclient apache-httpclient-4.x
我正在尝试通过REST模板发送gzip压缩请求.
我的要求格式: -
url = apiUrl + mymethod + "?api_key=" + apiKey;
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add("api_key", apiKey);
headers.add("Content-Type", "application/json");
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
headers.add("Accept-Encoding", "x-gzip");
HttpEntity<String> entity = new HttpEntity<String>("parameters",
headers);
ResponseEntity<GenericResponseDto> response = null;
try {
response = restTemplate.exchange(url, HttpMethod.GET, entity,
GenericResponseDto.class);
} catch (Exception e) {
throw new CustomException(e, aPIAuditTrail);
}
log.info("Response :"+response);
Run Code Online (Sandbox Code Playgroud)
发送此请求时收到如下响应消息: - "Response(code=401, message=gzip not passed as header parameters)"
如果我将请求标题更改为
headers.add("Accept-Encoding", "gzip");
Run Code Online (Sandbox Code Playgroud)
我得到例外: -
org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Illegal character …Run Code Online (Sandbox Code Playgroud)