• What is HTTP Basic authentication:
The desktop application also interacts with the Web server via the HTTP protocol, and the desktop application generally does not use cookies, but instead puts the ' username +:+ password ' in the header of the request with the Base64 encoded string. Authorization sent to the server.
The server will return a 401 error if password/Account error is required when opening a Web page prompting for an account and password.
HTTP BASIC Certification process:
1) The client sends a request to the server,
2) Because the request does not contain the authorization header, the server returns a 401 error to the client.
3) After the client has encoded the username and password with base64, it is sent to the server in the authorization header, and the authentication is successful.
4) The server will remove the username and password from the authorization header for verification, if verified by sending resources to the client as required.
http OAuth Authentication
OAuth for HTTP, is not the user name and password, but a token in the oauthorization header.
python case:
#python#Xiaodeng#http authoritative Guide 133#by adding an HTTP header to implement theImportUrllib,urllib2 fromBase64ImportEncodestringurl="'User="'passwd="'req=Urllib2. Request (URL) basestr=encodestring ('%s:%s'% (USER,PASSWD)) [: 1]req.add_header ('Authorization','Basic%s'%basestr) F=Urllib2.urlopen (req)#through Headler to achieveImportUrllib2password_mgr= Urllib2. Httppasswordmgrwithdefaultrealm ()#Create a password managerURL ="http://www.163.com/"password_mgr.add_password (None, URL, username, password)#Add a user name and password. If you know realm, use it instead of none.Handler =Urllib2. Httpbasicauthhandler (password_mgr) opener= Urllib2.build_opener (Handler)#Create openerA_url ='http://www.baidu.com/'Opener.open (A_url)#Open a URLUrllib2.install_opener (opener)#Install opener, Urllib2.urlopen will use it later.
Basic authentication of HTTP protocol