Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Token authentication

2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Some logins use cookie and some logins require token authentication.

Generally speaking, there are two forms of passing parameters in token, one is in the request header, and the other is using URL to pass parameters.

Here is an example to illustrate the token mode in the request header:

# Login

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

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

Print (r1.text)

Print (r1.status_code)

# obtain token after login

Dic1=json.loads (r1.text) or direct dict1=r1.json ()

Token1=dic1 ['token']

Print (token1)

# token is added to the request header to visit

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

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report