【问题标题】:Get user API key automatically while endpoint returns HTTP 401端点返回 HTTP 401 时自动获取用户 API 密钥
【发布时间】:2021-05-22 06:49:39
【问题描述】:

如果端点返回 HTTP 401,Postman 是否有办法通过调用登录端点自动获取该用户的新 API 密钥?在这种情况下,Postman 会加载结果并将 API 密钥存储在特定环境中的变量中。

【问题讨论】:

    标签: postman


    【解决方案1】:

    Postman 中的测试选项卡允许您编写一些 JS 代码来检索响应数据并允许您采取相应的行动。 然后postman API允许你在collection runner或者newman中设置下一个请求,这样你就可以正常调用登录请求了。

    基本上是这样的:

    const jsonData = pm.response.json()
    
    if (pm.response.code === 401) {
        pm.setNextRequest('login')
    }
    

    Here is some further reading about scripting in postman.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-29
      • 2019-01-02
      • 2021-08-03
      • 1970-01-01
      • 2013-11-11
      • 2022-08-20
      • 2014-11-13
      • 2018-10-29
      相关资源
      最近更新 更多