postman调用测试接口需要先登录

时间:2024-03-30 22:29:21

报错信息:{“code”:401,“data”:“Full authentication is required to access this resource”,“message”:“暂未登录或token已经过期”}
这里我的测试接口是get请求:http://localhost:8080/brand/listAll
登录的接口是post请求:http://localhost:8080/admin/login
直接调用get请求,上报401,未登录错误:
postman调用测试接口需要先登录
网上找到的方法是在浏览器中登录,从浏览器获取登录的cookie
postman调用测试接口需要先登录

然后调用post请求:
postman调用测试接口需要先登录
我没有前台,post的登录请求也没法通过浏览器登录,测试接口是get请求,方法不适应,但是有启发。
解决办法:
1.先使用登录接口http://localhost:8080/admin/login登录,获取token:

postman调用测试接口需要先登录
2.使用获取到的token发送get请求:
postman调用测试接口需要先登录
成功调用:
postman调用测试接口需要先登录