Java 如何在Spring Boot应用程序的请求头中发送GZIP(Accept;Encoding:;GZIP)参数?
我正试着发送Java 如何在Spring Boot应用程序的请求头中发送GZIP(Accept;Encoding:;GZIP)参数?,java,spring,rest,spring-boot,gzip,Java,Spring,Rest,Spring Boot,Gzip,我正试着发送 headers.add("Accept-Encoding", "gzip"); 在我的Spring boot应用程序中 我得到了这个例外 com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens 但是我需要发送gzip作为请求头 我
headers.add("Accept-Encoding", "gzip");
在我的Spring boot应用程序中
我得到了这个例外
com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens
但是我需要发送gzip作为请求头
我的Spring启动版本是“1.3.5.RELEASE”
请帮帮我
我的请求示例:
url = apiUrl + apiMethod + "?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.set("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);
log.info("Response :" + response.toString());
} catch (Exception e) {
throw new CustomException(e, aPIAuditTrail);
}
url=apirl+apiMethod+”?api_key=“+apiKey;
RestTemplate RestTemplate=新RestTemplate();
HttpHeaders=新的HttpHeaders();
标题。添加(“api_键”,apiKey);
添加(“内容类型”、“应用程序/json”);
setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
set(“接受编码”、“x-gzip”);
HttpEntityentity=新的HttpEntity(“参数”,标题);
ResponseEntityresponse=null;
试一试{
response=restemplate.exchange(url、HttpMethod.GET、entity、,
一般响应到类);
log.info(“响应:+Response.toString());
}捕获(例外e){
抛出新的CustomException(e,aPIAuditTrail);
}
它可能与标题无关。你能(a)共享控制器并请求示例,以及(b)尝试不使用标题吗?这是否有帮助:是的,我尝试过,但没有得到解决方案。但我从