Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

420
Vistas
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.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

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

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda