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

234
Views
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
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!