赞
踩
某响应体信息内容
{"status":1,"msg":"\u767b\u9646\u6210\u529f","result":{"user_id":139,"email":"","password":"519475228fe35ad067744465c42a19b2","paypwd":null,"sex":1,"birthday":978192000}
-
- var resp = responseBody;
- //打印响应信息
- console.log(resp);
-
- //可以根据响应信息进行判断,是否包含某个值
- var result = resp.includes("\\u767b\\u9646\\u6210\\u529f");
某响应头信息
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);
获取响应头里某个值
var header1 = postman.getResponseHeader("Set-Cookie");
由此方法我们可以将获取到的值设置成变量,比如说获取Cookie里的SessionId或者我们常说的token值,都可以用次方法获取。
获取SessionId,SessionId是在cookie信息里,所以我们需要获取cookie信息。
- var session = postman.getResponseCookie("PHPSESSID");
- console.log(session.value);
某响应信息
{"status":1,"msg":"\u767b\u9646\u6210\u529f","result":{"user_id":139,"email":"","password":"519475228fe35ad067744465c42a19b2","paypwd":...}
比如我们需要提取响应中password值
- //使用正则表达式对响应内容进行匹配提取
- var v1 = responseBody.match(new RegExp("password\":\"(.*?)\""));
- console.log(v[1]);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。