Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

411
Views
How to not escape form body characters in Spring RestTemplate when making a POST request?

I have following code where I am making a POST form request. The request body contains username and password. Password contains @ characters, which is replaced by RestTemplate with %40 and I am getting "unauthorized" error as the password is wrong now. Following is the debug info from bufferOutput(request body)

merchant_id=firstname+de-lastname%40gmail.com&password=%40Password

Here is the code snippet that is making the call.

MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
String url = "SOME_URL";
formData.add("username", "xay@gmail.com");
formData.add("password", "@name321");

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String,String>> requestEntity = new HttpEntity<MultiValueMap<String,String>>(formData,headers);

RestTemplate restTemplate = new RestTemplate();
        restTemplate.getMessageConverters()
                .add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
        restTemplate.exchange(url, HttpMethod.POST, requestEntity, Authentication.class,"321");

The question is how to tell restTemplate not to escape body data ? Note that the request has to be a post form request and I can not use UriComponentsBuilder to fix the problem.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I think you need to add a FormHttpMessageConverter to your RestTemplate rather than a StringHttpMessageConverter.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!