Basic authentication of HTTP protocol

Source: Internet
Author: User

• 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.