Postman发送请求时带上登录信息

正常情况下,没有登录验证等公共接口,用postman进行get或post请求都很方便,加上相应的参数就行。

但是对于某些接口,可能需要先登录后才能请求,这时如果按正常的思路请求,可能就会被拦截了。

对于这种情况,可以通过以下方式:

1. 打开浏览器,正常登录后,再请求你要的接口,应该能请求成功,这时查看请求头:

看了下请求头中,感觉最有用的可能就是这个Cookie了,所以尝试将它添加到postman的请求头中

2. 在postman请求头中添加Cookie信息

post :

服务器端是一个简单的接口:

<?php


namespace app\admin\controller;


use cmf\controller\AdminBaseController;
use think\facade\Request;

class UserController extends AdminBaseController
{
    public function index()
    {
        if(Request::isGet())
        {
            $data = Request::get();
            _return(0, 'suc', $data);
        }
        else
        {
            $data = Request::post();
            _return(0, 'suc2', $data);
        }
    }
}

_return()是我的一个简单封装,返回{code, msg, data}这种json结构

Guess you like

Origin blog.csdn.net/JoeBlackzqq/article/details/99671309