当前位置:   article > 正文

postman在接口请求之前先请求其他接口_postman怎么在请求前调用上一个request请求

postman怎么在请求前调用上一个request请求

Pre-request Script中获取另一个请求的返回数据

Pre-request Script中发送get请求

const reqshop = {
    url : "https://sewew/shops/" + pm.environment.get("sid") +"/neuron",
    method: 'GET',
    header: 'Authorization:Bearer '+pm.environment.get("flashcardToken")
}
pm.sendRequest(reqshop, function (err, response) {
    var resurl = response.json().url;
    var willremove="https://232m/#/?auth_token=";
    var token = resurl.replace(willremove,"");
    pm.environment.set("token", token);
});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

Pre-request script中发送post请求

const req = {
    url: 'https://wewe/account',
    method: 'POST',
    header: 'Content-Type:application/json',
    body: {
        mode: 'raw',
        raw: JSON.stringify(
        {
            "redirect": "/sites/",
            "username": "username",
            "password": "password",
            "autoLogin": true
        }
        )
    }
};
pm.sendRequest(req, function (err, response) {
    var flashcardToken = response.json().data.user.token
    pm.environment.set("flashcardToken", flashcardToken);
});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/631849
推荐阅读
相关标签
  

闽ICP备14008679号