简介:Requests 使用Python语言编写,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库。它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTTP 测试需求。Requests 的哲学是以 PEP 20 的习语为中心开发的,所以它比 urllib 更加 Pythoner。
一、请求方法类型
1、get请求:requests.get(‘url‘)
2、post请求:requests.post(“url/post”)
3、put请求:requests.put(“url/put”)
4、delete请求:requests.delete(“url/delete”)
5、head请求:requests.head(“url/get”)
6、options请求:requests.options(“url/get”)等
今天我们来讲解如何进行get、post方法的接口测试。
二、get请求
首先引用requests库和json库,因为我们使用的是requests进行接口测试的。
![1078042d365c3576cf469789cb73a8d7.png](https://i-blog.csdnimg.cn/blog_migrate/7f1aa1d4e6579854e50d89ef483de960.jpeg)
查看一下结果
![44cc91e9ffec95b8bb612426d27d6519.png](https://i-blog.csdnimg.cn/blog_migrate/c7cca5f2ababff11c8de13a48784e7b3.jpeg)
三、post请求
post请求和get请求不同的地方在于post请求需要传递body参数
![7c27f6cd7724b42b967b84cb5cf3840e.png](https://i-blog.csdnimg.cn/blog_migrate/1496e3ef951e0d006d7b142a39c22bff.jpeg)
这就是python实现get、post接口请求的方法
也可以使用工具进行接口测试,比如国产的接口测试工具apipost
使用apipost进行get请求
![cfc94cd2b592d68d4a548f36fb1f0926.png](https://i-blog.csdnimg.cn/blog_migrate/4918d40951d5d8aad124666f7ffad1a7.jpeg)
进行post请求
![a2422e221d11d7ffa3772d08bc86ff6c.png](https://i-blog.csdnimg.cn/blog_migrate/68345cb4e994779e39216610caa53796.jpeg)
还可以生成各种格式的接口文档比如:word格式的接口文档
![601e74aa23ad1d0d3917eb5e43f39249.png](https://i-blog.csdnimg.cn/blog_migrate/7968682c9f410d93a28dedd938fa7d4c.jpeg)
国产接口工具apipost下载地址:https://www.apipost.cn