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}}

 

 

 

需要注意的是,設置全局後,需要發送請求

 

完畢!!! 

 

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