我正在尝试向不受控制的服务器发出GET请求,该服务器在Content-Type
标头中返回无效值:“ Application / json; charset =”。
当我尝试进行GET调用时,Spring尝试解析该值时会抛出InvalidMimeTypeException,因为它正确地希望在=符号后应有一个实际的字符集。
restTemplate.getForObject(new URI(DATASOURCE), String.class); // throws InvalidMimeTypeException when attempting to parse response
是否可以将RestTemplate配置为忽略响应中返回的任何内容类型标头?我无法控制正在查询的服务器。 (春季启动版2.2.0.RELEASE。)
org.springframework.http.InvalidMediaTypeException: Invalid mime type "Application/json; charset=": 'value' must not be empty
at org.springframework.http.MediaType.parseMediaType(MediaType.java:574) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:966) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.web.client.HttpMessageConverterExtractor.getContentType(HttpMessageConverterExtractor.java:135) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:92) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:744) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:717) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:336) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]