Я пытаюсь позвонить от потребителя услуг (проект 1) поставщику услуг (проект 2) с многокартовыми данными с использованием Spring Rest Service, но я получаю 400 ошибок плохого запроса. Обе службы работают в моей машине. Ниже приведен мой фрагмент кода. Я не могу службу предоставить код, так как это используется сторонней системой. @Override
public void callFileAPI(byte[] pdf) {
String response = null;
HttpStatus httpStatus = null;
try {
MultiValueMap map = new LinkedMultiValueMap();
map.add("file", new ByteArrayResource(pdf));
//map.add("request", "");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
String url = "http://xxxx/api/mpFile";
final RestTemplate restTemplate = new RestTemplate();
HttpEntity requestEntity = new HttpEntity(map, headers);
response = restTemplate.postForObject(url, requestEntity, String.class);
//response = restTemplate.postForObject(url, map, String.class);
} catch (HttpStatusCodeException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
Поставщик услуг:
@RequestMapping(value = "/mpFile", method = RequestMethod.POST)
public @ResponseBody String mpFile(@RequestPart MultipartFile file) {
String respStr = "OK";
try {
System.out.println("File obj : "+file);
} catch(Exception e) {
e.printStackTrace();
}
return respStr;
}
ошибка:
org.springframework.web.client.HttpClientErrorException: 400 Bad Request
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:86)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:708)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:661)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:621)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:388)
Подробнее здесь: https://stackoverflow.com/questions/732 ... rt-request
Spring 400 Плохой запрос при отправке Multipart запроса ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Всегда получаю 400 - плохой запрос при публикации данных в отдыхе/JAX -RS
Anonymous » » в форуме JAVA - 0 Ответы
- 17 Просмотры
-
Последнее сообщение Anonymous
-