postman接口测试之获取响应数据


一、获取响应行中的状态码

//获取数据
var code=responseCode.code;
//打印code
tests[code]=true;

如下图所示:

 

二、获取响应行中状态码名字

//获取数据
var codename=responseCode.name;
//打印
tests[codename]=responseCode.name;

如下图所示:

 

三、获取响应时间

//获取响应时间
var time=responseTime;
tests[time]=true;

如下图所示:

  

四、获取响应头的Content_type

//获取响应头部信息的Content-Type
var header=postman.getResponseHeader('Content-Type');
//打印
tests[header]=true;

如下图所示:

 

五、获取响应cookies中的value值,括号中填写cookies的name值

//获取cookies中的value值
var cookies=postman.getResponseCookie('cookies的name值').value;
//打印
tests[cookies]=true;

如下图所示:

 

  六、获取响应正文

//获取body
var body=responseBody;
//打印
tests[body]=true;

如下图所示:

 

七、正则表达式截取响应body里面的属性值

//获取body
var body=responseBody;
//获取body中的title
var title=body.match(new RegExp('<title>(.+?)</title>'));
//打印title
tests[title]=true;

如下图所示:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM