how can i view an encrypted bin file without breaking it's encoding using ajax?

36 Views Asked by At

the code

var xhr0 = new XMLHttpRequest();
xhr0.open("get", 'page/file.bin', true);
xhr0.onreadystatechange = function() {
    if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
        console.log("data:")
        console.log(xhr0.response)

        }
}
xhr0.send();

one of the response headers of the page

Content-Type: application/x-download;charset=ISO-8859-1

although i can't determine the exact encoding of the file cause it's encrypted . i need to view the file the same as it's.. binary ( hexadecimal view ) .

1

There are 1 best solutions below

0
mooooooon On BEST ANSWER

by using a response type

just like this

var xhr0 = new XMLHttpRequest();
xhr0.open("get", 'page.bin', true);
xhr0.responseType =  "blob";
xhr0.onreadystatechange = function() {
    if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
        console.log("data:")
        var blob1 = xhr0.response
        console.log(blob1)
            }
}
xhr0.send();

it will look like something like this image