嗨,我想用RestTemplate来消耗这个控制器 我该怎么办
@PostMapping(produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public Object convertToUsingParam(
@ApiParam(value = "The input document to convert.", required = true) @RequestParam("data")
final MultipartFile inputFile,
@ApiParam(value = "The document format to convert the input document to.", required = true)
@RequestParam(name = "format")
final String convertToFormat,
@ApiParam(value = "The custom options to apply to the conversion.")
@RequestParam(required = false)
final Map<String, String> parameters) {
LOGGER.debug("convertUsingRequestParam > Converting file to {}", convertToFormat);
return convert(inputFile, convertToFormat, parameters);
}
我以这种方式使用
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("data", new ByteArrayResource(bodyContent));
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
restTepmlate.getMessageConverters().add(new FormHttpMessageConverter());
try {
ResponseEntity<byte[]> response = restTepmlate
.exchange("http://10.20.14.247:8081/lool/convert-to/pdf",
HttpMethod.POST,
requestEntity,
byte[].class);
} catch (HttpClientErrorException e) {
e.printStackTrace();
}
但它返回
org.springframework.web.client.HttpClientErrorException:406空 在org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:94) 在org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:79) 在org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63) 在org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:766) 在org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:724) 在org.springframework.web.client.RestTemplate.execute(RestTemplate.java:680) 在org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:600)