Created
October 20, 2011 12:58
-
-
Save KushalP/1301082 to your computer and use it in GitHub Desktop.
Capture the 401 Authentication code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // A lazy raw JS function to quickly play with this. | |
| function getHTTPObject() { | |
| if (typeof XMLHttpRequest != 'undefined') { | |
| return new XMLHttpRequest(); | |
| } | |
| try { | |
| return new ActiveXObject("Msxml2.XMLHTTP"); | |
| } catch (e) { | |
| try { | |
| return new ActiveXObject("Microsoft.XMLHTTP"); | |
| } catch (e) {} | |
| } | |
| return false; | |
| } | |
| window.onload = function() | |
| { | |
| var http = getHTTPObject(); | |
| if (http) { | |
| // You'll need to fill out url, user, and pass manually. | |
| // It breaks somewhere between this line and the next. It does | |
| // however correctly catch the Auth dialog. It just can't go | |
| // passed it. | |
| this.http.open("get", url, false, user, pass); | |
| this.http.send(""); | |
| if (http.status == 200) { | |
| // do something as the url has been authed | |
| } else { | |
| alert("Incorrect username and/or password."); | |
| } | |
| } else { | |
| alert("Couldn't build HTTPObject."); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment