背景介绍
现在许多初级开发调试B/S模式的程序的时候想要跟踪网页请求,用户往往有很多的开源工具或者手写代码请求,我比较常用的一种软件是postman,他是Chrome插件代表作之一。
下载安装
Postman可以分两种方式下载,第一种直接去官网下载可以执行的exe文件,
https://www.getpostman.com/downloads/,
第二种方式是直接使用Chrome浏览器下载插件,
基础功能
postman主要功能
从图中可以看到,postman的免费版本就提供了非常全面的功能,下面将简单的介绍postman的使用。
设置环境变量
有时需要在不同的环境下跑相同的测试,此时可以通过设置环境变量来动态选择。点击右上角的设置按钮:
设置环境变量
使用这些键值的时候只需要加上两个花括号引用key{{url_base}}/username解析完后建立多个环境时,key通常都是相同的,只是value不同创建好所有环境后,在跑用例的时候在右上角下拉列表选择需要的环境就好。
请求
postman界面分为两部分:左边的sidebar 右边的request builder:快速创建几乎所有的请求
有些headers和cookies是保密的,如:
- Accept-Charset 2.Accept-Encoding 3.Access-Control-Request-Headers4.Access-Control-Request-Method5.Connection6.Content-Length7.Cookie8.Cookie 29.Content-Transfer-Encoding10.Date11.Expect12.Host13.Keep-Alive14.Origin15.Referer16.TE17.Trailer18.Transfer-Encoding19.Upgrade20.User-Agent21.Via
添加cookie
有些接口在调用时,需要添加权限,例如:你访问一个接口,没有cookie,直接跳转到登录页。
这个时候可以通过添加cookie的方式跳过验证,例如:
这样即可跳过验证,成功发送请求。
Background Introduction
Nowadays, when many junior developers debug B/S mode programs and want to track web requests, users often have many open source tools or write code requests by hand. One software I commonly use is Postman, which is one of the representative Chrome plugins.
Download and Installation
Postman can be downloaded in two ways. The first is to go directly to the official website to download the executable exe file,
https://www.getpostman.com/downloads/,
The second way is to use the Chrome browser to download the plugin directly,
Basic Functions
Postman Main Functions
As you can see from the image, Postman's free version provides very comprehensive functions. Below I will briefly introduce the use of Postman.
Setting Environment Variables
Sometimes you need to run the same tests in different environments. At this time, you can dynamically select by setting environment variables. Click the settings button in the upper right corner:
Setting Environment Variables
When using these key-value pairs, you only need to add two curly braces to reference the key {{url_base}}/username. After parsing and creating multiple environments, the keys are usually the same, only the values are different. After creating all environments, when running test cases, just select the required environment from the dropdown list in the upper right corner.
Requests
The Postman interface is divided into two parts: the sidebar on the left and the request builder on the right: quickly create almost all requests
Some headers and cookies are confidential, such as:
- Accept-Charset 2.Accept-Encoding 3.Access-Control-Request-Headers 4.Access-Control-Request-Method 5.Connection 6.Content-Length 7.Cookie 8.Cookie 2 9.Content-Transfer-Encoding 10.Date 11.Expect 12.Host 13.Keep-Alive 14.Origin 15.Referer 16.TE 17.Trailer 18.Transfer-Encoding 19.Upgrade 20.User-Agent 21.Via
Adding Cookies
Some interfaces require adding permissions when called. For example: when you access an interface without a cookie, it redirects directly to the login page.
At this time, you can skip verification by adding cookies, for example:
This way you can skip verification and successfully send the request.