在 Debian 上“Postman 调试脚本”一般有几种常见场景,我分别说明,你可以对号入座。
Postman 的脚本分为:
console.log 调试在脚本里写:
console.log("token:", pm.environment.get("token"));
console.log("response:", pm.response.json());
然后在 Postman 中打开:
View → Show Postman Console
或快捷键:
Ctrl + Alt + C
发送请求后,在 Console 里看输出。
pm.* 调试变量console.log(pm.variables.get("name"));
console.log(pm.environment.get("host"));
console.log(pm.collectionVariables.get("baseUrl"));
if (!pm.response.code === 200) {
throw new Error("响应状态码不是 200");
}
chmod +x Postman-linux-x64-*.AppImage
./Postman-linux-x64-*.AppImage
sudo snap install postman
如果你是用 Newman 跑 Postman 脚本:
sudo apt update
sudo apt install nodejs npm
sudo npm install -g newman
newman run collection.json
Newman 默认会输出 console.log 内容。
如果想更详细:
newman run collection.json --verbose
console.log(pm.request.url.toString());
console.log(pm.request.headers.toString());
console.log(pm.response.text());
try {
let json = pm.response.json();
console.log(json);
} catch (e) {
console.error("JSON 解析失败", e);
}
可以是:
如果是 curl 调试:
curl -X POST http://localhost:8080/api \
-H "Content-Type: application/json" \
-d '{"name":"test"}' -v
为了更精准帮助,你可以补充:
我可以一步一步帮你定位。