Search code examples
springpostresttemplate

POST request with Content-Type application/x-www-form-urlencoded and


My requirement is very simple.

Call POST request with id and password. Header has Content-Type = application/x-www-form-urlencoded and data is also passed as urlencoded like below

Response is coming in xml format.

I tried a lot of examples from everywhere but nothing seems to be working. It gives me back 401 Unauthorized which is an error that target API throws if request is not in proper format.


Solution

  • http://zetcode.com/java/getpostrequest/

    Exactly what I needed. Java HTTP POST request with HttpURLConnection section on the page did the work.