博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Http Basic Authorizaition验证
阅读量:4170 次
发布时间:2019-05-26

本文共 649 字,大约阅读时间需要 2 分钟。

Http Basic Authorizaition验证的原理详见 

 


python实现: 

import urllib2 

import sys 

import re 

import base64 

from urlparse import urlparse 


theurl = 'http://api.minicloud.com.cn/statuses/friends_timeline.xml' 


username = 'qleelulu' 

password = 'XXXXXX'  # 你信这是密码吗? 


base64string = base64.encodestring( 

                '%s:%s' % (username, password))[:-1] #注意哦,这里最后会自动添加一个\n 

authheader =  "Basic %s" % base64string 

req.add_header("Authorization", authheader) 

try: 

    handle = urllib2.urlopen(req) 

except IOError, e: 

    # here we shouldn't fail if the username/password is right 

    print "It looks like the username or password is wrong." 

    sys.exit(1) 

thepage = handle.read() 


原理就是添加了请求头Authorization

转载地址:http://iikai.baihongyu.com/

你可能感兴趣的文章
商务智能-基本方法-特征与角度
查看>>
软件项目管理系统-项目管理-模块定义-开发笔记
查看>>
工作流审批平台-业务申请-申请书一览
查看>>
商务智能-基本方法-数据钻取
查看>>
C++程序员技术需求规划(发展方向)
查看>>
嵌入式100题(017):malloc的底层实现
查看>>
嵌入式100题(018):在1G内存的计算机中能否malloc(1.2G)?为什么?
查看>>
嵌入式100题(019):指针与引用的相同和区别;如何相互转换?
查看>>
嵌入式100题(040):什么是三次握手
查看>>
嵌入式100题(037):Http1.1和Http1.0的区别
查看>>
嵌入式100题(038):HTTPS与HTTP的一些区别
查看>>
嵌入式100题(042):为什么服务端易受到SYN攻击?
查看>>
嵌入式100题(043):什么是四次挥手
查看>>
嵌入式100题(044):为什么客户端最后还要等待2MSL?
查看>>
嵌入式100题(045):为什么建立连接是三次握手,关闭连接确是四次挥手呢?...
查看>>
嵌入式100题(028):static的用法(定义和用途)
查看>>
嵌入式100题(027):char和int之间的转换
查看>>
嵌入式100题(029):const常量和#define的区别(编译阶段、安全性、内存占用等)...
查看>>
嵌入式100题(030):volatile作用和用法
查看>>
嵌入式100题(033):TCP、UDP的优缺点
查看>>