zoukankan      html  css  js  c++  java
  • 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;

    如下图所示:

     
  • 相关阅读:
    spring boot指定外部配置的坑
    beego 批量删除问题
    spark 安装
    HttpServletRequest 获取cookie
    k8s 代码生成
    k8s 各种示例
    mysql-operator
    k8s Docker私有仓库认证
    Failed to introspect annotated methods on class 异常
    P6272 没有人的算术
  • 原文地址:https://www.cnblogs.com/puhongjun/p/12865239.html
Copyright © 2011-2022 走看看