柚子快報邀請碼778899分享:Postman提取響應(yīng)數(shù)據(jù)
柚子快報邀請碼778899分享:Postman提取響應(yīng)數(shù)據(jù)
1、獲取響應(yīng)體
某響應(yīng)體信息內(nèi)容
{"status":1,"msg":"\u767b\u9646\u6210\u529f","result":{"user_id":139,"email":"","password":"519475228fe35ad067744465c42a19b2","paypwd":null,"sex":1,"birthday":978192000}
var resp = responseBody;
//打印響應(yīng)信息
console.log(resp);
//可以根據(jù)響應(yīng)信息進行判斷,是否包含某個值
var result = resp.includes("\\u767b\\u9646\\u6210\\u529f");
?2、獲取響應(yīng)頭
某響應(yīng)頭信息
Content-Type?→text/html; charset=UTF-8
Transfer-Encoding?→chunked
Connection?→keep-alive
X-Powered-By?→PHP/5.6.20
Set-Cookie?→is_mobile=0; expires=Tue, 30-May-2023 04:40:30 GMT; Max-Age=3600; path=/
var header = responseHeaders;
console.log(header);
?獲取響應(yīng)頭里某個值
var header1 = postman.getResponseHeader("Set-Cookie");
?
由此方法我們可以將獲取到的值設(shè)置成變量,比如說獲取Cookie里的SessionId或者我們常說的token值,都可以用次方法獲取。
獲取SessionId,SessionId是在cookie信息里,所以我們需要獲取cookie信息。
var session = postman.getResponseCookie("PHPSESSID");
console.log(session.value);
?3、提取響應(yīng)信息某個數(shù)據(jù)
某響應(yīng)信息
{"status":1,"msg":"\u767b\u9646\u6210\u529f","result":{"user_id":139,"email":"","password":"519475228fe35ad067744465c42a19b2","paypwd":...}
比如我們需要提取響應(yīng)中password值
//使用正則表達式對響應(yīng)內(nèi)容進行匹配提取
var v1 = responseBody.match(new RegExp("password\":\"(.*?)\""));
console.log(v[1]);
?
?
柚子快報邀請碼778899分享:Postman提取響應(yīng)數(shù)據(jù)
參考閱讀
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點和立場。
轉(zhuǎn)載請注明,如有侵權(quán),聯(lián)系刪除。