How to send body content as raw JSON and not form-data in Spring Boot RestTemplate
Thanks to @Alex Salauyou based on his comment using HashMap instead of MultiValueMap solved the problem. Here is the changes need to be done:
HashMap<String, String> bodyParam = new HashMap<>();
bodyParam.put("amount", request.getAmount());
bodyParam.put("destinationNumber",request.getDestinationNumber());
How to send POST request through RestTemplate with custom parameter in header
From the discussion in the comments, it's quite clear that your request object isn't correct. If you are passing a plain string containing folder name, then you don't need a MultiValueMap
. Just try sending a string,
String data = "/public/"
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
HttpEntity<String> request = new HttpEntity<String>(
data, headers);
String url = "http://192.168.1.51:8080/pi/FilesServlet";
restTemplate.getMessageConverters().add(new FormHttpMessageConverter());
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
String response = restTemplate
.postForObject(url, request, String.class);
sending GET request via REST template with JSON request body getting failed with binding binding element must be a struct error?
rest template doesn't support get request with body . for more details you can refer this article.
If you are on Java 11 I would suggest you to use java.net.HttpClient which will fulfill your need.
Related Topics
In Java, How to Combine Two Json Arrays of Objects
How to Check If a Java 8 Stream Is Empty
How to Properly Re-Run Spring Boot Application from Eclipse
Sharing a Variable Between Multiple Different Threads
Delete Not Working in Hibernate/Spring Data
How to Get the Parent Element Name of a Child Element in Json
How to Externalize Application.Properties in Tomcat Webserver for Spring
Add Additional Rules to the Compare Method of a Comparator
Get Enum Values as List of String in Java 8
How to Change the Colors of Text and Background for Cmd in Java
Create List of Object from Another Using Java 8 Streams
How to Mock Resultset and Populate It Using Mockito in Java
Handling the Null Value from a Resultset
Use Only One Bufferedreader Object to Read Multiple Files in Java
How to Find the Number of Times If or Else Code Has Executed