Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

423
Visualizações
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 Respostas
Responde à pergunta

0

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

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda