【发布时间】:2021-03-14 02:56:30
【问题描述】:
MultiValueMap<String, String> body_data = new LinkedMultiValueMap();
body_data.add("param1", {param1});
...
WebClient webClient = WebClient.builder().baseUrl(api_url+request_url)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
.build();
String result = webClient.post().contentType(MediaType.APPLICATION_FORM_URLENCODED)
.bodyValue(BodyInserters.fromFormData(body_data)).retrieve().bodyToMono(String.class).block();
然后它返回
org.springframework.web.reactive.function.client.WebClientRequestException: Content type 'application/x-www-form-urlencoded' not supported for bodyType=org.springframework.web.reactive.function.BodyInserters$DefaultFormInserter; nested exception is org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'application/x-www-form-urlencoded' not supported for bodyType=org.springframework.web.reactive.function.BodyInserters$DefaultFormInserter
对此有什么建议吗? content-type 应该是 application/x-www-form-urlencoded。
【问题讨论】: