How to POST form data with Spring RestTemplate?

前端 未结 4 1152
栀梦
栀梦 2020-11-29 16:57

I want to convert the following (working) curl snippet to a RestTemplate call:

curl -i -X POST -d \"email=first.last@example.com\" https://app.example.com/hr         


        
4条回答
  •  天涯浪人
    2020-11-29 17:31

    Your url String needs variable markers for the map you pass to work, like:

    String url = "https://app.example.com/hr/email?{email}";
    

    Or you could explicitly code the query params into the String to begin with and not have to pass the map at all, like:

    String url = "https://app.example.com/hr/email?email=first.last@example.com";
    

    See also https://stackoverflow.com/a/47045624/1357094

提交回复
热议问题