V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
guin
V2EX  ›  问与答

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

  •  
  •   guin · 32 天前 · 733 次点击
    这是一个创建于 32 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我想给一个项目中所有的请求加公共的请求体或拼接公共的 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 也没给我正确答案,求大佬解答

    目前尚无回复
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   5034 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 05:45 · PVG 13:45 · LAX 21:45 · JFK 00:45
    ♥ Do have faith in what you're doing.