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?