const headers = new Headers();
headers.set(
"Authorization",
"Basic " + base64.encode(username + ":" + password)
);
fetch(url, { method: "GET", headers: headers })
.then(res => {
console.log("res", res.statusCode);
});
res.send("success");
I am trying get a jpeg image file from an url using API URL. When I try to save the file, I am getting following error:
(node:18636) UnhandledPromiseRejectionWarning: FetchError: invalid json response body at [API url] reason: Unexpected token � in JSON at position 0
The url is working when using the Advance Rest Client chrome web application to display the image. But it is not working in node.js using above code. Can someone help me to sort this? That would be appreciated.