1

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);



  })
mots
  • 195
  • 1
  • 4
  • 22

2 Answers2

8

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'

Somethig like:

let axiosConfig = {
  headers: {
      'Content-Type' : 'application/json; charset=UTF-8',
      'Accept': 'Token',
      "Access-Control-Allow-Origin": "*",

  }
};
Community
  • 1
  • 1
Amit Kumar Khare
  • 565
  • 6
  • 17
0

send your phone number as number i.e without quotes otherwise it will be read as string

const postData = {                                
totalSum: 5000,
event_id: 7,
phone_number: 1298515352
};
Mak Sr
  • 303
  • 4
  • 14