I am trying to GET the binary data of a file from an API; I must make this request using JavaScript and I cannot modify the API in any way.
I am currently using the following approach;
function getUserFile() {
$.ajax({
type: 'GET',
url: userData.file.link,
beforeSend: function(request) {
request.setRequestHeader('Accept', 'application/octet-stream');
request.setRequestHeader('Authorization', 'Bearer ' + authToken);
},
contentType: 'application/json',
success: function(data) {
// Do something with data
},
error: function(errorThrown) {
console.log(errorThrown);
}
});
}
When I trigger this request from inside the browser it fails and returns a 406. This is occurring because the browser (I believe?) is adding the */* value to my Accept header. It must only contain application/octet-stream for the API to accept the request.
Is it at all possible to remove this extra header value, or disable it from being added to the request in the first place?
EDIT:
Running both this and the real API call through JSFiddle does not append the */* value to the Accept header. Running the same code from a standard HTML document does add the value. What is different about these two that might be causing the value to be omitted on one while not the other?
EDIT: The aspx page in question is running either JQuery 1.5.x or 1.8.x