学习笔记2:postman 的基本使用

时间:2023-03-09 22:42:16
学习笔记2:postman 的基本使用

1、get 请求

请求接口:http://xx.xx.xx.xx/api/user/stu_info

请求参数:stu_name

请求参数是放在请求 URL 里的,点击 Params添加参数,key 输入参数名stu_name,value 输入参数的值如 test1

学习笔记2:postman 的基本使用

2、post请求

请求接口:http://xx.xx.xx.xx/api/user/login

请求参数:usernamepasswd

参数是放在 body 里的,body 里选择 form-data 的数据格式,添加 usernamepasswd参数:

学习笔记2:postman 的基本使用

3、入参为 json 格式的 post 请求

请求接口:http://xx.xx.xx.xx/api/user/add_stu

请求参数:json 类型的数据,格式如下:

{
"name":"把啦啦啦",
"grade":"金牛座",
"phone":18564567890,
"sex":"女",
"age": 999,
"addr": "浙江杭州"
}

postman 里切换到 Body 里选择 json 的数据格式,填写参数内容:

学习笔记2:postman 的基本使用

4、postman 中添加cookie

请求接口:http://xx.xx.xx.xx/api/user/gold_add

请求参数:需要添加 cookie 才能操作, cookie 中 key 为用户名, value 为用户登录返回的 session。

postman 中 cookie 在 header 里添加,如图:

学习笔记2:postman 的基本使用

5、添加 header

请求接口:http://xx.xx.xx.xx/api/user/all_stu

请求参数:带有 header,header 名为Referer, 值为http://api.nnzhp.cn/

学习笔记2:postman 的基本使用

6、文件上传

请求接口:http://xx.xx.xx.xx/api/file/file_upload

请求参数:一个文件

postman 里 Body 数据格式选择 form-data,参数类型选择 File,然后就可以进行文件上传的操作了,如图:

学习笔记2:postman 的基本使用