apifox: get请求参数含特殊字符或者中文,需要进行URL转码

 以下是URL转码的脚本:

//将公钥进行转码

// 获取环境变量值
const rawValue = pm.environment.get("publicKey");
//打印未转码前的公钥值
console.log("公钥未转码前的值为:", rawValue);


// 对参数中的值进行URL转码
const encodedValue = encodeURIComponent(rawValue);
console.log("公钥转码后的值为:", encodedValue);

// 将转码后的值赋值给变量
pm.variables.set("encodedParam", encodedValue);
// 将转码后的值设为环境变量
pm.environment.set("urlkey",encodedValue );

// 获取环境变量值urlkey
const kkey = pm.environment.get("urlkey");
// 将urlkey的值打印出来
console.log("打印后的urlkey值为:", kkey);

 

posted @ 2025-06-20 16:45  羊孩  阅读(147)  评论(0)    收藏  举报
返回顶端