I am trying to make a request to an api with node-fetch. I've followed the documentation but it doesn't seem to do anything.
I have modified the options and it seems that nothing has changed. Headers and body are ignored.
When I test with postman and see the request in the console, it is empty and returns nothing.
This is the code :
let myheaders ={
'Content-type': 'application/json',
}
let raw = {
"user": "user",
"pw": "pw"
};
let defaultOptions = {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
//mode: 'cors', // no-cors, *cors, same-origin
//credentials: 'include', // include, *same-origin, omit
headers: myheaders,
body: JSON.stringify(raw) // body data type must match "Content-Type" header
}
const response = await fetch("url",defaultOptions);
const responseText = await response.text();
console.log(responseText);
res.send(responseText);
//.then(response => response.text());
//.then(result => console.log(result));
//.catch(error => console.log('error', error));
//res.json(response);
The postman console displays :
Request headers
-Postman Token : 'token'
Request body
-Ø
I have tried everything that has been suggested in posts similar to this one and cannot find the solution.
thanks