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

235
Visualizações
Axios POST request - setting headers

I am trying to mimic a form submit with an Axios post request - to be more precise, I am trying to turn this:

<form method="POST" action="https://testpaymentgateway...">
    
<input type="text" name="amount" value="1000"/>
    
<input type="submit" text="submit"/>
    
</form>

into something like this:

let paymentData = new FormData();

paymentData.append('amount','1000');

axios.post('https://testpaymentgateway...', paymentData, {
    
headers: {
     
'content-type': 'application/x-www-form-urlencoded',
    
'sec-fetch-mode': 'navigate'
    
}
    
})
    
.then(function (response) {
    
console.log(response);
    
})
    
.catch(function (response) {
    
console.log(response);
    
});

The first example with manually submitting the form works ok, while the axios post request returns a CORS error. I have compared the two requests and found that some of the headers are different, however, the axios request doesn't seem to set the headers I'm trying to set, the content-type is always "multipart/form-data" and sec-fetch-mode is always "cors". I have tried different ways of setting the headers object, but none of them are working. Any idea why this might be happening?

about 4 years ago · Juan Pablo Isaza
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