我们在开发和调试网络程序或是基于B/S模式的系统的时候,往往需要借助一些网络请求工具来监视或测试接口,如我常用的Firebug。但是在我们自动化API测试和多样化API接口的开发环境中,就需要一款好用的API自动化测试工具。PostMan就是一款这样的接口调试测试利器。PostMan以前是以Chrome版本提供的,现在官方已经不在维护Chrome版本了,所以我们现在可以使用Native版本。下面我就简单介绍下这块工具的使用。
下载安装
官方下载地址:https://www.postman.com/downloads/
Postman支持Windows,MAC,Linux系统
下载后,一路按提示安装完成,Postman安装完成自动运行,界面如下
![d91f4c44d66362eefc16de6f8b099c02.png](https://img-blog.csdnimg.cn/img_convert/d91f4c44d66362eefc16de6f8b099c02.png)
Postman启动界面
使用Postman需要先申请一个账号,然后登录,登录后界面如下:
![e70f42206c79222e633727233a331821.png](https://img-blog.csdnimg.cn/img_convert/e70f42206c79222e633727233a331821.png)
Postman主界面
界面介绍
![1c9ffe54aaef4e46aa73a0da446f32f1.png](https://img-blog.csdnimg.cn/img_convert/1c9ffe54aaef4e46aa73a0da446f32f1.png)
Postman操作界面
发生请求后,可以查看相关返回状态,执行事件,返回文件大小,Cookies,Headers等
![6f1b32dbe78e1c45a6c24270715b6287.png](https://img-blog.csdnimg.cn/img_convert/6f1b32dbe78e1c45a6c24270715b6287.png)
Postman还可以根据返回信息类型,自动格式化返回Body格式
![6a6e3f11975a27aeccf8e5e22d602d5e.png](https://img-blog.csdnimg.cn/img_convert/6a6e3f11975a27aeccf8e5e22d602d5e.png)
测试接口参数和数据设置
1、Params:及URL后面带的参数
![51c069b1cd30c1044503d79dd57773ce.png](https://img-blog.csdnimg.cn/img_convert/51c069b1cd30c1044503d79dd57773ce.png)
2、Authorization:接口相关认证相关信息
![6ff9d26242fdaf633498bcec85b53652.png](https://img-blog.csdnimg.cn/img_convert/6ff9d26242fdaf633498bcec85b53652.png)
3、Headers:请求头部参数
![53f687b8f7265478a6fb7ae32a288a50.png](https://img-blog.csdnimg.cn/img_convert/53f687b8f7265478a6fb7ae32a288a50.png)
4、Body:请求提交的数据
表单请求数据:
![cd34b25a399d3f80f333f4b8bfaae91f.png](https://img-blog.csdnimg.cn/img_convert/cd34b25a399d3f80f333f4b8bfaae91f.png)
表单请求数据
JSON等其他数据格式提交
![0a834eaa0b1887213c10a04afd869459.png](https://img-blog.csdnimg.cn/img_convert/0a834eaa0b1887213c10a04afd869459.png)
二进制文件提交
![e26cb4d308d85c70fff60ee0117d59a3.png](https://img-blog.csdnimg.cn/img_convert/e26cb4d308d85c70fff60ee0117d59a3.png)
针对接口,批量测试
我们先向某个集合批量添加测试接口
![1b6050a7b5d4233ffcc33bad58389cb2.png](https://img-blog.csdnimg.cn/img_convert/1b6050a7b5d4233ffcc33bad58389cb2.png)
然后我们点击运行
![4af8760e648af4fe0dca6130a6c31d7c.png](https://img-blog.csdnimg.cn/img_convert/4af8760e648af4fe0dca6130a6c31d7c.png)
打开如下窗口
![fe84b8b961cf01cc7f782c4d85feae14.png](https://img-blog.csdnimg.cn/img_convert/fe84b8b961cf01cc7f782c4d85feae14.png)
点击运行,获得测试结果
![84b59ca1ad5f2a5d91cf801c9903456b.png](https://img-blog.csdnimg.cn/img_convert/84b59ca1ad5f2a5d91cf801c9903456b.png)
好了,Postman基础使用就介绍到这,当然Postman的功能不止这些,后面有时间再介绍。