I am trying to send data with axios but it sends a response that is not expected. When I use postman to make the same request,it successfully sends a notification to my phone, here is the postman response:
{
"status": 200,
"success": true,
"message": "Notification sent to your phone to make payment",
"data": null
}
but with axios, the notification is not sent to my phone, here is the axios response:
{
status: 200,
success: true,
message: 'Tickets Sold Out',
data: null
}
Here is my axios code:
const postData = {
totalSum: 5000,
event_id: 7,
phone_number: '1298515352'
};
let axiosConfig = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
"Access-Control-Allow-Origin": "*",
}
};
axios({
method: 'post',
url: 'url',
headers: axiosConfig,
data: postData
})
.then((res) => {
const message = res.data;
console.log(message);
})
Which content type are you sending with POSTMAN? I think its in JSON format. but in axios you are sending
Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
check your server for accepted content type and also try to send 'Content-Type' : 'application/json'
let axiosConfig = {
headers: {
'Content-Type' : 'application/json; charset=UTF-8',
'Accept': 'Token',
"Access-Control-Allow-Origin": "*",
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With