我希望能够将查询参数添加到如下所示的预请求脚本 sendRequest url,但一直无法弄清楚如何做到这一点.... 我尝试使用不同的选项但无济于事。感谢您的帮助!
pm.sendRequest({
url: pm.globals.get("base_url") + bankNum + "/loans/" + loan14,
method: 'GET',
header: {
'Authorization': '********',
},
}, function (err, response) {
console.log(response.json());
});
答案 0 :(得分:0)
pm.sendRequest(({
url: "https://reqres.in/api/users?page=2",
method: 'GET',
header: {
'Authorization': '********',
},
}), function (err, response) {
console.log(response.json());
});
您将查询作为 ?name=value 传递
您还可以通过创建普通请求然后在控制台中打印该请求来生成所需的请求。要打印请求结构,请使用:
console.log(JSON.stringify(pm.request.toJSON(),null,2))
现在复制:
pm.sendRequest({
"url": {
"protocol": "https",
"path": [
"api",
"users"
],
"host": [
"reqres",
"in"
],
"query": [
{
"key": "page",
"value": "2"
}
],
"variable": []
},
"header": [
{
"key": "Postman-Token",
"value": "f3e48848-4001-4f1e-862c-b316c85dd3e7",
"system": true
},
{
"key": "Host",
"value": "reqres.in",
"system": true
}
],
"method": "GET",
"body": {}
}
, function (err, response) {
console.log(response.json());
});