Postman登陆权限给postman的请求添加cookie以及使用interceptor拦截浏览器发送的请求

60次阅读

共计 1029 个字符,预计需要花费 3 分钟才能阅读完成。

要使用 postman 测试开发的接口时,遇到了登陆权限的问题,本项目的权限是根据 cookie 中的某个值来做的判断,那么就需要在发送 post 请求的时候附带 cookie 内容

通过 interceptor 拦截请求

  • 拦截器的好处是,不需要手动填写所有参数,而是直接截取到某个 http 请求的左右参数设置
  1. 点击该按钮,弹出拦截器相关设置窗口
  2. 点击 interceptor 按钮
  3. 点击 ON 打开拦截器,此时右侧的应该出现 CONNECTED 的绿色小点,如果是 UNCONNECTED 的灰色小点,可以参考文档
  4. 设置在哪里保存拦截的请求
  5. 对拦截的请求做筛选

设置不同的 http 请求公用的 cookie

  • 通过在 chrome 中查看线上的接口调用信息,发现登陆权限是通过 cookie 中的 session 来确定的,这样就可以把这条 cookie 在 postman 中设置出来,就可以在 postman 中测试 post 请求了。
  1. 点击按钮,弹出 cookie 设置的窗口
  2. 输入 domin 的名称
  3. 保存 domin
  4. 添加具体的 cookie 参数,每一条都要在这里添加一下
  5. 前面的 cookie 的 name,后面的是 value
  6. 保存该 domin 下的这一条 cookie

常见问题

拦截器是 UNCONNECTED 的灰色小点
  • 官方提到了这样的解决方案

官方提到了这样的解决方案

  • 核心内容是:

    • The cookies and domains will be populated automatically. Can you confirm the following:

      1. Chrome is open, and has the Interceptor extension installed (v0.2.26)
        谷歌浏览器是打开状态,且已经安装 Interceptor 扩展
      2. You’ve completed the installation steps for the bridge
        已经完成安装 bridge
      3. The Interceptor Status isn’t updating to‘Interceptor Connected’even after restarting Chrome
        重启谷歌浏览器后,Interceptor 应用,处于 连接中 的状态
    • Interceptor 是一个用于拦截 chorme 浏览器的 http 请求的拦截器,可以把相关请求发送给 postman 软件。
    • Interceptor Bridge 是用来建立浏览器和 postman 软件之间信息连接通道的一个小应用,需要手动安装。
  • 根据该方案,就可以使得 UNCONNECTED 的灰色小点变成 CONNECTED 的绿色小点
正文完
 0