token authentication

Some log in using cookie, some need to login token authentication.

token parameter passing are generally two forms, one in the request header, one is using the URL parameter passing.

Examples token embodiment described herein at the request header:


#log in

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

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

print(r1.text)

print(r1.status_code)


# After obtaining the login token

dic1 = json.loads (r1.text) or directly dict1 = r1.json ()

token1=dic1['token']

print(token1)


#token added to the request header, the access

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

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


Guess you like

Origin blog.51cto.com/11009785/2435340