我开发了一个Chrome,它使用XMLHttpRequest将带有用户名/密码的GET HTTP请求发送到基本身份验证的URL,以便之后可以"自动登录"(因为Chrome会为HTTP basic-auth缓存凭据) .
这是我使用的代码:
var xml = new XMLHttpRequest();
xml.open('GET',<url>,false,<username>,<password>)
xml.send('');
Run Code Online (Sandbox Code Playgroud)
经过一些额外的研究,我发现它可能与Chrome 19不支持用户名:pwd @ url语法用于验证基本身份验证的URL,因为当我发送XMLHttpRequest时,我在Google Chrome的js控制台中看到了这一点:
获取http:// user:pass@domain.com 401(未经授权)
有谁知道这是一个错误还是Chrome停止支持此功能?
我的功能
function autoLogin(domain, user, password) {
var httpAuth;
if (window.XMLHttpRequest) {
httpAuth = new XMLHttpRequest(); // code for IE7+, Firefox, Chrome, Opera, Safari
}
else if (window.ActiveXObject) {
httpAuth = new ActiveXObject("Microsoft.XMLHTTP"); // code for IE6, IE5
}
else {
alert("Seu browser não suporta autenticação xml. Favor autenticar no popup!");
}
var userName = domain + "\\" + …Run Code Online (Sandbox Code Playgroud)