Need help on RestTemplate Post Request with Body Parameters?

后端 未结 1 1808
深忆病人
深忆病人 2021-02-20 11:34

I have a rest api url and submitted the same as POST request with body (user name, password, other parameters) via Rest Client (restclient-ui-2.4-jar-with-dependencies) and it g

相关标签:
1条回答
  • 2021-02-20 12:28

    The above converters Ex: "MarshallingHttpMessageConverter" are not required.

    MultiValueMap<String, String> parametersMap = new LinkedMultiValueMap<String, String>();
    parametersMap.add("username", "test");
    parametersMap.add("password", "test123");
    parametersMap.add("id", "1234");
    

    For Post:

    restTemplate.postForObject(url, parametersMap, Employee.class);
    
    • url is String - rest api URL
    • parametersMap - MultiValueMap
    • Employee - object which needs to be converted from the JSON response

    For Get:

    restTemplate.getForObject(url,  class object, variablesMap);
    
    • url is : String - rest api URL
    • variablesMap - Map
    • class object - object which needs to be converted from the JSON response
    0 讨论(0)
提交回复
热议问题