Ajax获取网页文件
function getBase64(imgUrl) {
window.URL = window.URL || window.webkitURL;
var xhr = new XMLHttpRequest();
xhr.open("get", imgUrl, true);
// 至关重要
xhr.responseType = "blob";
xhr.onload = function () {
if (this.status == 200) {
//得到一个blob对象
var blob = this.response;
// console.log("blob", blob);
// 至关重要
let oFileReader = new FileReader();
oFileReader.onloadend = function (e) {
// 此处拿到的已经是 base64的图片了
let base64 = e.target.result;
base64 = "<p id=''Base64Text''>"+base64+"</p>";
document.getElementsByTagName("body")[0].innerHTML = base64;
return base64;
};
oFileReader.readAsDataURL(blob);
}
}
xhr.send();
}
我在网络上找到一个这样的JS代码,可以得到网络文件的base64,一开始可以的,可后来不知道网站开发人员做了什么限制,获取不到了,有什么办法可以突破吗?