HTTP Basic Authentication

时间:2023-03-09 08:09:59
HTTP Basic Authentication

Client端发送请求, 要在发送请求的时候添加HTTP Basic Authentication认证信息到请求中,有两种方法:
1. 在请求头中添加Authorization:
    Authorization: "Basic 用户名和密码的base64字符串"
      其中, 用户名和密码中间先用:号隔开, 然后做base64编码, 如'Basic dGVzdDpwd2Q=' header的用户名为test, 密码为pwd
2. 在url中添加用户名和密码:
    http://userName:password@api.somesite.com/recent_events.xml

Server端验证逻辑, 通过检查 Authorization header的内容, 该header中包含用户名和密码信息, 然后验证用户名和密码, 如果没通过验证, 直接返回401 错误,

Python server实现
http://*.com/questions/4287019/stuck-with-python-http-server-with-basic-authentication-using-basehttp
     
Basic authentication 客户端端示例 (使用 requests)   
http://docs.python-requests.org/en/master/user/authentication/

Basic authentication 客户端端示例 (使用 urllib2)
http://www.cnblogs.com/QLeelulu/archive/2009/11/22/1607898.html