我試圖使用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