0

im trying to send a post request from my firebase function but the post request never runs. In the firebase console everything seems to be fine.

  var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
  var xhttp = new XMLHttpRequest();
  xhttp.open("POST", url, true);
  xhttp.setRequestHeader("Content-type", "application/json");
  xhttp.setRequestHeader("Authorization", "key="+ key);
  let res = {
   "notification": {
    "title": "Test",
    "body": "Notificación enviada desde Firebase"
   },
   "to": to,
  }
  xhttp.send(JSON.stringify(res))
  console.log(xhttp)
  return (xhttp);

i dont know what im doing wrong

Tomas
  • 1
  • 2
  • Maybe this will be of use [How Firebase Cloud functions handle HTTP post method?](https://stackoverflow.com/q/42995433/387194) – jcubic Mar 31 '20 at 15:18

1 Answers1

0

I'd suggest you to implement in your code the logic for when the request is finished as it is described here, so you can debug what is being sent by the server you're trying to send this request.

Finally, if you are not very familiar XMLHttpRequest, you could give it a try to axios in your firebase functions (Promise based HTTP client),

axios.post('/your_endoint', {
    param1: 'hello',
    param2: 'there'
})
.then(function (response) {
    console.log(response);
})
.catch(function (error) {
    console.log(error);
});

to see more details for axios config you can visit the Github page details

chinoche
  • 335
  • 1
  • 8