postman關聯 含獲取請求頭的方法

2022-03-18 06:24:39 字數 1375 閱讀 5587

在tests裡面輸入指令碼

var jsondata = json.parse(responsebody);

postman.setenvironmentvariable("message", jsondata.code);

獲取響應的資料中 code 的值,然後賦值給字元「message」  如: 響應資料直接是  

踩坑地方:

這裡的指令碼要看響應的返回形式來修改

如:var jsondata = json.parse(responsebody);

postman.setenvironmentvariable("uid", jsondata.result.uid);    這裡響應返回的格式裡面是 result 裡面還有陣列 所以 獲取uid 指令碼是 jsondata.result.uid

在獲取關聯引數的時候可以設定乙個environment,把獲取的值放進去,給下個請求呼叫 ,沒有設定environment貌似獲取引數沒儲存到

(這裡直接建立乙個獲取值後,就自己會記錄下來的了)

參考: 

後記:獲取請求頭的寫法:

設定為全域性變數的寫法:

postman.setglobalvariable("uid",uid)

獲取響應資訊

後台響應:

取mobile的方法

var jsondata=json.parse(responsebody);

var mobile=jsondata.data.mobile

postman.setenvironmentvariable("mobile",mobile)  可以參考:

另外一種寫法: 

//獲取響應資料json物件

var jsondata = pm.response.json();

//從響應資料提取出token

var token = jsondata.token;

//設定token

pm.environment.set("token", token);

php CURL 請求頭和響應頭獲取

1.從curl中獲取響應頭 ocurl curl init 設定請求頭,有時候需要,有時候不用,看請求 是否有對應的要求 返回 response header,該選項非常重要,如果不為 true,只會獲得響應的正文 curl setopt ocurl,curlopt header,true 是否不需...

php CURL 請求頭和響應頭獲取

1.從curl中獲取響應頭 ocurl curl init 設定請求頭,有時候需要,有時候不用,看請求 是否有對應的要求 返回 response header,該選項非常重要,如果不為 true,只會獲得響應的正文 curl setopt ocurl,curlopt header,true 是否不需...

curl的請求頭與響應頭獲取

1.從curl中獲取響應頭 ocurl curl init 設定請求頭,有時候需要,有時候不用,看請求 是否有對應的要求 返回 response header,該選項非常重要,如果不為 true,只會獲得響應的正文 curl setopt ocurl,curlopt header,true 是否不需...