Nandana S V
Nandana S V

Reputation: 19

Webclient springboot posting values in map variable to an url using

I am a beginner in Springboot .I have some values in my map variable and I need to post it to an external url from Springboot app

/**
 * Function to post data to external url
 * @param extracted
 * @return 
 */
private ResponseEntity<String> postData(Map<String, String> extracted) {

    WebClient webClient = WebClient.create("third party base url");
    String response =  webClient.post()
            .uri("/thirdPartyEndPoint")                     
            .accept(MediaType.APPLICATION_JSON )
            .contentType(MediaType.APPLICATION_FORM_URLENCODED)
            .retrieve()
            .body(extracted)
            .block();
    return new ResponseEntity<>(response, HttpStatus.OK);
}

The variable extracted in the above code will be having data like

{
"Data 1": "1",
"Data 2": "0000000000000000000000000000",
"JSON Data": "{\"0\":{\"timeStamp\":\"Mon Jan 19 18:15:21 IST 1970\",\"value\":263.76},\"1\":{\"timeStamp\":\"Mon Jan 19 18:15:21 IST 1970\",\"value\":263.76},\"2\":{\"timeStamp\":\"Mon Jan 19 18:15:21 IST 1970\",\"value\":263.76},\"3\":{\"timeStamp\":\"Mon Jan 19 18:15:21 IST 1970\",\"value\":263.76}}",
"Data 3": "80725010",
}

The method body(Map<String,String>) is undefined for the type WebClient.ResponseSpec

Can someone point me to how I can do this?The data should be posted as form data. Also how to post it without the escape characters? enter image description here

Upvotes: 1

Views: 582

Answers (0)

Related Questions