postmain-全局变量设置

 

测试工具postmain 全局请求参数设置

Pre-request-Script中添加脚本

postman.setGlobalVariable("secretKey", "mysecret123456");
secretKey = postman.getGlobalVariable("secretKey");

 

上面表示请求设置一个安全的key

 

postman.setGlobalVariable("time", Math.round(new Date().getTime()));
time = postman.getGlobalVariable('time');
// 设置一个时间 - 需要注意的是,这里设置过时间后,当前时间在请求时时不会变的, 如果请求接口签名会有时间限制,则需要在调用的接口中单独设置时间参数。 也是在Pre-request-Script中添加当前脚本语句,因为Pre-request-Script在请求时才会触发。

在Header中的写法

{{time}} 

 

---- Postman,header里面加时间戳的方法

{{$timestamp}}
# 这是默认10位的时间戳。位数大于10位则用0补全
{{$timestamp}}000

 

在Params中的写法

{{time}}

 

 

 

需要注意的是,设置全局后,需要发送请求

 

完毕!!! 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章