我正在尝试使用JAR文件作为有效负载进行POST服务调用,我得到以下错误
找不到合适的HttpMessageConverter请求类型 [org.springframework.util.LinkedMultiValueMap]和内容类型 [应用/八位字节流]
我尝试的代码如下,这里的任何帮助都会很棒
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("*.jar").getFile());
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.AUTHORIZATION, authHeader);
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);
LinkedMultiValueMap<String, Object> payLoad = new LinkedMultiValueMap<String, Object>();
payLoad.add("file", new FileSystemResource(file));
HttpEntity<LinkedMultiValueMap<String, Object>> httpEntity = new HttpEntity<LinkedMultiValueMap<String, Object>>(payLoad, headers);
try {
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<Object> response = restTemplate.postForEntity(url, Object.class);
} catch (RestClientException ex) {
ex.printStackTrace();
}
答案 0 :(得分:0)
听起来你必须添加一个HttpMessageConverter
来处理八位字节流。尝试在WebConfig
@Override
public void configureMessageConverters(
List<HttpMessageConverter<?>> converters) {
messageConverters.add(new ResourceHttpMessageConverter());
super.configureMessageConverters(converters);
}