Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.6K
Views
how to post body x-www-form-urlencoded using webclient?
    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();

and it returns

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

Any suggestion for this? content-type should be application/x-www-form-urlencoded.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

We can use BodyInserters.fromFormData for this purpose:

WebClient client = WebClient.builder()
            .baseUrl("SOME-BASE-URL")
            .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
            .build();
    
return client.post()
            .uri("SOME-URI)
            .body(BodyInserters.fromFormData("username", "SOME-USERNAME")
                    .with("password", "SONE-PASSWORD"))
                    .retrieve()
                    .bodyToFlux(SomeClass.class)
                    .onErrorMap(e -> new MyException("messahe",e))
            .blockLast();

In another form:

MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
formData.add("username", "XXXX");
formData.add("password", "XXXX");

String response = WebClient.create()
    .post()
    .uri("URL")
    .contentType(MediaType.APPLICATION_FORM_URLENCODED)
    .body(BodyInserters.fromFormData(formData))
    .exchange()
    .block()
    .bodyToMono(String.class)
    .block();
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!