赞
踩
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);
});
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); });
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。