I'm trying to use an HTTP request in JavaScript to retrieve a file from the Slack API. I managed to get the url_private_download
of the file, but if I try to make an HTTP GET request using that URL, I get an error in the console saying that: Failed to load url_private_download: Response for preflight is invalid (redirect)
.
Here's my code:
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
console.log(xmlHttp.responseText);
}
};
xmlHttp.open("GET", url_private_download, true);
xmlHttp.setRequestHeader("Authorization", "Bearer " + my_slack_token);
xmlHttp.setRequestHeader('Access-Control-Allow-Headers','*')
xmlHttp.send(null);