温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

token鉴权

发布时间:2020-06-08 20:29:55 来源:网络 阅读:469 作者:爱与梦想 栏目:软件技术

有些登录使用cookie,有些登录需要token验证。

token传参一般有两种形式,一种是在请求头中,一种是使用URL传参。

这里举例说明一下请求头中的token方式:


#登录

param1={'username':'xxx','password':'xxxx'}

r1=requests.post('http://127.0.0.1:12306/login',data=param1)

print(r1.text)

print(r1.status_code)


#获取登录后token

dic1=json.loads(r1.text) 或者直接 dict1=r1.json()

token1=dic1['token']

print(token1)


#token添加到请求头中,访问

header={'Authorization':'Bearer '+token1}

r2=requests.get('http://127.0.0.1:12306/api/tasks',headers=header)


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI