使用postman做接口测试,可以选择请求方式,可以直接输入参数和header,可以编写测试结果的代码,判断是否通过测试
下图为填写接口测试地址、填写接口的参数,点击send发送请求
其中,Params 和 body需要说明一下,因为Params和body都是可以输入参数的,那这两个有什么区别?
Params:对应的是get请求方式,在这里输入的参数,会显示在接口地址后(?参数名+参数值)
body:对应的是Post请求方式,这里输入的参数,就是接口发送传输的参数了
接口发送请求后,会接收到接口返回的结果,此时,就可以核对接口文档返回的结果对不对啦。
某些接口是要登录之后才能操作的,这种接口要怎么测试呢?
- 获取到登录成功的cookies
- 在需要登录状态的接口的header里加上一个cookie
怎么获取cookie?
登录接口为例,需要正常的用户名和密码,发送请求,看接口返回的接口,到cookies里查看是否有cookie
需要用到cookie的地方,在header下创建一个cookie