你好,我已经获得了请求系统的代码,但 RestTemplate 在标头中始终添加 utf8
示例
POST /v1/documents/validation HTTP/1.1
Accept: application/json
Content-Type: multipart/form-data;charset=UTF8;boundary=gs7Tmph96b0PDkFCrOo9Y7EhtqqV3ok2agluTF
如何删除 charset=UTF8 ?
这是我的代码
RestTemplate restTemplate = getRestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.add("Content-Type", "multipart/form-data");
headers.add("FSE-JWT-Signature", getHashSignature());
headers.add("Authorization", "Bearer " + getBearerToken());
LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
FileSystemResource value = new FileSystemResource(new File(fileName));
map.add("file", value);
map.add("requestBody", requestBody.toString());
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(map, headers);
错误
"title":"InvalidRequestContent","status":400,"detail":"Request content not conform to API specification: UTF-8;boundary=Kpj8KEbP1NBn3tLmsWgbj8O6LlcGNzyp60ejoi4A"
默认情况下,如果您使用 Exchange(),RestTemplate 会添加 utf-8。我不知道为什么。
使用 postForObject,即类似这样的:
String serverEndPoint = "https://httpbin.org/post";
HttpHeaders headers = new HttpHeaders();
headers.setContentType("multipart/form-data");
HttpEntity<Whatever> entity = new HttpEntity<>(whateverObject, headers);
String result = restTemplate.postForObject(serverEndPoint, entity, String.class);
你是如何解决这个问题的?