有些登录使用cookie,有些登录需要token验证,token传参一般有两种形式,一种是在请求头中,一种是使用URL传参

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

#登录
param1={'username':'xxx','password':'xxxx'}
r1=requests.post('http://127.0.0.1:3000/login',data=param1)
print(r1.text)
print(r1.status_code)
#获取登录后token
dic1=json.loads(r1.text)
token1=dic1['token']
print(token1)
#token添加到请求头中,访问
header={'Authorization':'Bearer '+token1}

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

#结果
访问成功

 

相关文章:

  • 2022-12-23
  • 2021-04-12
  • 2022-12-23
  • 2021-07-10
  • 2022-02-24
  • 2022-12-23
猜你喜欢
  • 2022-03-01
  • 2021-04-08
  • 2021-08-05
  • 2021-04-20
  • 2021-04-19
  • 2022-01-22
相关资源
相似解决方案