我试图使用XMLHttpRequest
检索Javascript中图像的数据。使用XMLHttpRequest下载二进制数据,不需要overrideMimeType
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.celticfc.net/images/doc/celticcrest.png");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
var resp = xhr.responseText;
console.log(resp.charCodeAt(0) & 0xff);
}
};
xhr.send();
该数据的第一个字节应该是0x89
,然而任何高值中的字节返回作为0xfffd
(0xfffd & 0xff
为0xfd
)。
问题如this one提供使用overrideMimeType()
函数的解决方案,但是在我使用的平台(Qt/QML)上不支持这种解决方案。
如何正确下载数据?
您是否尝试过使用base64编码? – cvsguimaraes
我会如何尝试? – funkybro
似乎这是不可能的;我将使用Qt/C++代替原生本地下载。 – funkybro