Normal view

There are new articles available, click to refresh the page.
Today — 6 November 2025Main stream

mac 上的 RapidAPI 有 postman 的那种 pre-request 功能吗?

By: guin
6 November 2025 at 11:25
guin:

我想给一个项目中所有的请求加公共的请求体或拼接公共的 url 参数,postman 中可以通过 pre-request 写这种脚本

let commonBody = {};
let token = pm.collectionVariables.get("token");
try {
    commonBody = {
        "device": "iPhone18,3",
        "mobileid": "B47F6F75-4648-413B-8C77-957441FA8614",
        "token": token,
        "uid": 186032,
        "version_ios": 1
    };
} catch(e) {}

// 获取当前请求 body
let currentBody = {};
try {
    currentBody = JSON.parse(pm.request.body.raw);
} catch(e) {}

// 合并
const finalBody = {
    ...commonBody,
    ...currentBody
};

// 更新 body
pm.request.body.update(JSON.stringify(finalBody));

 let url = pm.request.url.toString();

  // 判断 URL 是否已有参数
if (url.indexOf('?') === -1) {
    url += `?token=${encodeURIComponent(token)}`;
} else {
    url += `&token=${encodeURIComponent(token)}`;
}

pm.request.url = url;

请问 RapidAPI 有这种功能吗?看了那个 js script 扩展好像只能给单个请求加?而且还报错,不会弄,问 ai 也没给我正确答案,求大佬解答

❌
❌