Postman automatically logs in, request with token

write picture description here write picture description here

add an environment

Manage Environments(右上角的齿轮) => Add => 填写环境的名称 => Add

Add login interface

# 比正常的请求多设置一下 "Tests"
# 将登录接口返回的response中的token加入环境变量, 如:
pm.environment.set("token", JSON.parse(responseBody).data.authorization);

add a collection

1. New collection (左侧 目录) 
2. 填写名称,如:"需要token的请求" 
3. 切换到选项卡"Authorization"
4. 选择相应的 TYPE
5. Token 中填写 {{token}}
6. 点击Create 创建集合

Add a request that requires a token

在刚创建的集合中添加的请求, Headers中都会自动添加 token, 如果token失效, 重新请求一下登录接口即可

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324378166&siteId=291194637