Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 强制Spring RestTemplate忽略响应';s内容类型标题_Java_Spring_Resttemplate - Fatal编程技术网

Java 强制Spring RestTemplate忽略响应';s内容类型标题

Java 强制Spring RestTemplate忽略响应';s内容类型标题,java,spring,resttemplate,Java,Spring,Resttemplate,我正试图向我无法控制的服务器发出GET请求,该请求在内容类型标题中返回无效值:“Application/json;charset=” 当我尝试执行GET调用时,Spring在尝试解析该值时抛出InvalidMimeTypeException,因为它正确地期望在=号后面应该有一个实际的字符集 restTemplate.getForObject(new URI(DATASOURCE), String.class); // throws InvalidMimeTypeException when at

我正试图向我无法控制的服务器发出GET请求,该请求在
内容类型
标题中返回无效值:“Application/json;charset=”

当我尝试执行GET调用时,Spring在尝试解析该值时抛出InvalidMimeTypeException,因为它正确地期望在=号后面应该有一个实际的字符集

restTemplate.getForObject(new URI(DATASOURCE), String.class); // throws InvalidMimeTypeException when attempting to parse response
是否可以将RestTemplate配置为忽略响应中返回的任何内容类型头?我无法控制正在查询的服务器。(弹簧护套2.2.0.释放。)

您实现了一个定制。这里有一个。我想您可以重用JSON转换器并注册自定义内容类型

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]