How to post request with spring boot web-client for Form data for content type application/x-www-form-urlencoded

Niraj Sonawane

How To use spring boot webclient for posting request with content type application/x-www-form-urlencoded sample curl request with content type `application/x-www-form-urlencoded'

--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=XXXX' \
--data-urlencode 'password=XXXX'

How Can i send same request using webclient?

Niraj Sonawane

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();
    

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Spring - wrong encoding POST request with x-www-form-urlencoded

How to send post request with x-www-form-urlencoded body

Spring Boot - Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

How to perform a GET request with application/x-www-form-urlencoded content-type in Go?

Http Put request with content type application/x-www-form-urlencoded not working in Spring

spring web client post form data of Long type

Jersey client Post Request with x-www-form-urlencoded Fails

RestSharp defaulting Content-Type to application/x-www-form-urlencoded on POST

how to post data in node.js with content type ='application/x-www-form-urlencoded'

How do I post data using okhttp library with content type x-www-form-urlencoded?

Post 'x-www-form-urlencoded' content with aurelia-fetch-client

Swift - How to send POST request with "x-www-form-urlencoded" content-type

How is Laravel decoding HTTP request body Content-Type: application/x-www-form-urlencoded when using api call

How do I get raw request body using servicestack with content-type set to application/x-www-form-urlencoded?

How to POST content as application/x-www-form-urlencoded

Sending post request from axios with "Content-Type" : "application/x-www-form-urlencoded" gives an 401 Unauthorized response

my request failed when the post 'content-type' is application/x-www-form-urlencoded and * form field param= { <this is a json object>}

How to send a POST request with Content-Type "application/x-www-form-urlencoded"

How to send post request with content-type x-www-form-urlencoded android retrofit

angular http post with 'Content-Type': 'application/x-www-form-urlencoded' and responseType: 'text'

RestAssured : annot determine how to serialize content-type application/x-www-form-urlencoded. How to create request with key/value structure?

Order of request parameters for content-type application/x-www-form-urlencoded in Spring MVC

Angularjs $http.post to contact form 7 with content type application/x-www-form-urlencoded

Akka HTTP how to POST singleRequest with Content-Type application/x-www-form-urlencoded

How to escape + in post call content type as application/x-www-form-urlencoded

How test Post request with custom object in content type application/x-www-form-urlencoded?

How to send x-www-form-urlencoded in a post request in webclient?

How to do a post request using FORM-DATA or x-www-form-urlencoded with Android?

Sending a form urlencoded POST request with Ktor Client?