问题
I have a directory on a website that is password protected via htaccess. I want to be able to open this web page through my application without having the user enter the password but rather do it programatically.
For instance, is there a way I can embed the login information in the URL? Such as http://www.mypage.com/page.html?htaccesspassword=asdasdas
thanks!
回答1:
scheme://username:password@host/path
回答2:
Although I think that authentication through the URL, as described by Ignacio Vazquez-Abrams, is much simpler, another approach might be setting the Authorization
header.
I'm assuming you're using Basic authentication.
The Authorization
header looks something like this:
Authorization: Basic Base64EncodedCredentials
Where Base64EncodedCredentials
is the username and password encoded with the Base 64 algorithm in the format
username:password
More information about it here: http://en.wikipedia.org/wiki/Basic_access_authentication
来源:https://stackoverflow.com/questions/9780656/open-htaccess-password-protectected-page-with-no-prompts