美文网首页
postman pre-request script 记录

postman pre-request script 记录

作者: ambition_timid | 来源:发表于2021-08-03 11:08 被阅读0次

http get
http post
set get var
urlencode
set header / param

// var host = pm.environment.get("var");
var host = '10*******:8081';
console.log(host);

// const csrfTokenServlet = {
// url: {{oauth-server}}/oauth2/v3/token?,
// method: 'GET'
// };

const postRequest = {
url: http://${host}/${path}?,
method: 'POST',
header:['Content-Type:application/x-www-form-urlencoded', 'Cookie:111111111'],
body: {
mode: 'x-www-form-urlencoded',
raw: "a=b&c=d"
}};

pm.sendRequest(postRequest, (err, response) => {
if (err) {
console.log(err);
} else {
pm.environment.set("at", response.json()['at']);
console.log(response.json()['at'])
}
});

pm.environment.set('at_url_encode', encodeURIComponent(pm.environment.get("at")));

// let paramValue = 'CwAAAAAAjZNgeYGiE***'
// pm.request.url.query.add('at=' + paramValue);

pm.request.url.query.add('at=' + pm.environment.get("at_url_encode"));
pm.request.headers.query.add('at=' + pm.environment.get("at_url_encode"));

相关文章

网友评论

      本文标题:postman pre-request script 记录

      本文链接:https://www.haomeiwen.com/subject/sdasvltx.html