前言
本篇文章将介绍postman的基础用法,基本能涵盖80%的后端请求用法。包括如何模拟登录,使用postman发送get、post请求,postman上传文件,postman下载文件
新建分组
新建一个分组,用来保存一个项目的请求,方便下次调试使用。

Get请求
Get请求比较简单,基本上只需填写地址栏以及Parmts参数,这里不做过多介绍,我们将重点放在post请求

Post请求
Post请求我们主要关注两个部分,Headers和Body。
Headers(请求头 模拟登录)
我们可以通过设置Cookie来实现模拟登录并发送请求。同时我们还可以设置编码格式、模拟浏览器信息、系统型号信息等。
如下图,当直接请求系统时,系统返回未登录。原因是的请求并未带上系统所需要的cookie数据。我们可以在页面先进行一次登录,通过f12中Application的cookies获取参数,最后在postman的Headers中设置参数进行模拟登录请求。


Body(请求体)
我们使用请求提提交数据,最常用的提交数据方式包括:
x-www-form-urlencoded(重点)
绝大部分post请求使用这个提交方式,但他不适合于提交文件流请求。
该请求方式的数据将被使用URLencoding编码。比如汉字“丁”,utf8编码在十六进制下是0xE4B881,最后他将被以字符串“%E4%B8%81”的方式传输,大小从3个字节变成了9个字节。因此其不适用于提交大容量数据请求。

multipart/form-data(上传文件)
使用postman上传文件,首先我们需要将格式切换成form-data,其次在参数的右方下拉选择File。


下载文件

网友评论