admin管理员组文章数量:1321236
I'd like to check if a URL is protected by a Http Basic Authentication using javascript. Here is what I have so far :
function showFailure(){ alert("FAILED ") }
function showSuccess(){ alert("SUCCESS") }
var myRequest = new Request({
url: 'http://localhost/access_protected_HTTP_BASIC',
method: 'get',
onSuccess: showSuccess,
onFailure: showFailure
}).send();
But that actually opens the browser login popup to access the resource. Is there a way not to trigger that popup?
Thanks!
Note : I use mootools in this example but I'd take any javascript example that does the trick :)
I'd like to check if a URL is protected by a Http Basic Authentication using javascript. Here is what I have so far :
function showFailure(){ alert("FAILED ") }
function showSuccess(){ alert("SUCCESS") }
var myRequest = new Request({
url: 'http://localhost/access_protected_HTTP_BASIC',
method: 'get',
onSuccess: showSuccess,
onFailure: showFailure
}).send();
But that actually opens the browser login popup to access the resource. Is there a way not to trigger that popup?
Thanks!
Note : I use mootools in this example but I'd take any javascript example that does the trick :)
Share Improve this question asked Oct 21, 2010 at 1:30 NhaolioNhaolio 1451 gold badge2 silver badges6 bronze badges2 Answers
Reset to default 7Based on the answer to a similar question, you can manually pass a username and password when sending a request. (And according to the MooTools Docs, the user
and password
parameters do exactly this.)
Further, the XMLHttpRequest
spec says:
If authentication fails, Authorization is not in the list of author request headers, request username is non-null, and request password is non-null, user agents must not prompt the end user for their username and password.
This means you can set a dummy username and password, and the browser won't prompt the user. If you get back a 401 status code, it means authorization is required.
all you should need to do is add a header Authorization: Basic *Base64EncodedString*
where *Base64EncodedString*
is base64Encode(username+':'+password)
it should be easy enough to find a base64encode function out there. YMMV
本文标签: Control HTTP basic authentication using javascriptStack Overflow
版权声明:本文标题:Control HTTP basic authentication using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742098570a2420694.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论