Postman/Apifox usage tutorial

1. Interface navigation instructions

Insert image description here
Insert image description here

2. Send the first request

http://www.weather.com.cn/data/sk/101010100.html

Insert image description here

3. Basic functions of the tool

3.1 Common types of interface requests

Common interfaces include the following four types:They are the interface containing query parameters, the interface of form type, the interface of json type and the interface containing uploaded files.The following describes these four types of interfaces and how to request them in postman.

3.1.1 Interface request for query parameters

What are query parameters?

The so-called query parameters are actually the part after the question mark (?) in the URL address, which is called the query parameter.
For example: http://cx.shouji.360.cn/phonearea.php?number=13012345678 In this interface, the query parameter is: number=13012345678 And this part is composed of key-value pairs, the format It is: key1=value1&key2=value2. If there are multiple sets of key-value pairs, they should be separated by &.

Request using Postman/Apifox
Insert image description here
Insert image description here

Insert image description here

3.1.2 Form type interface request

What is a form?
We all know that when sending an HTTP request, a request generally contains three parts, namely request line, request header, and request body.

Different interfaces have different data types of the request body. The more common one is the form type. So what is the form type? A simple understanding is to check Content-Type in the request header. If its value is: application/x-www-form-urlencoded, it means that the data submitted by the client is submitted in the form of a form. See picture below:
Insert image description here

How to request?
We only need to fill in four parameters, which are (refer to the picture above):

  • Request method: POST
  • 请求URL:http://localhost/index.php?m=Home&c=User&a=do_login&t=0.21942974229794432
  • Request header: Content-Type: application/x-www-form-urlencode
  • Request body: username=13088888888&password=123456&verify_code=8888

Insert image description here

3.1.3 Form request for uploading files

When doing interface testing, we often encounter interfaces that require uploading files, such as updating avatars on WeChat. This requires using: multipart/form-data. It is also a form, but it supports both form requests and file uploads. The data in its request message is often as follows.

POST http://localhost/index.php/home/Uploadify/imageUp/savepath/head_pic/pictitle/banner/dir/images.html HTTP/1.1  
Content-Type: multipart/form-data  
  
file=a1.jpg

How to request this type of interface in postman? Let’s first analyze the parameters that need to be filled in.
Request method: POST
Request URL: http://localhost/index.php/home/Uploadify/imageUp/savepath/head_pic/pictitle/banner/dir /images.html
Request type: multipart/form-data
Request body: file=a1.jpg

Implementation steps:

  1. Open Postman/Apifox and create a new request.
  2. Set the above four parameters in the request and click the Send button. Note: To set the request body type in Postman/Apifox, you need to select body-> form-data. In file, select the File type and then upload the local file.
    View response data.
  3. View response data.
    Insert image description here

3.1.4 json type interface request

This should be the most common situation in interface testing, that is, the request body type is json. Let's take a look at this request message.

POST http://xxx/api/sys/login HTTP/1.1  
Content-Type: application/json;charset=UTF-8  
  
{
    
    "account":"root","password":"123456"}

Based on the above message, we can analyze that we only need to fill in four parameters in Postman/Apifox, as follows:
Request method: POST< a i=2> Request address: http://xxx/api/sys/login Request body type: json Request body data: {"account": "root","password":"123456"}


Give the same example
Insert image description here

3.2 Interface response data analysis

Response data is the result returned after processing by the server after sending the request. The response consists of three parts, namely status line, response header, and response body. Let’s take a look at postman’s response data display.

Insert image description here

Response data display in postman:

  • Status line: Status: 200 OK
  • Response header: Headers + Cookies. It should be noted that Cookies are included in the response header, but for the sake of clarity, the tool will display them separately.
  • Response body: Body

So what role does this data play in our interface testing?

  • Body and Status are the focus of our interface testing. Generally speaking, we will verify the data in the response body and the response status code.
  • Test Results allows us to view the execution results of the assertion after we write the assertion, so this is also very useful to us.
  • Time and Size are when we do performance testing, we can make a simple judgment on the performance of the interface being tested based on these two parameters.

Next, let’s focus on several display themes in Body, namely: Pretty, Raw, and Preview.

  • Pretty: Translated into Chinese, it means pretty. That is to say, the returned Body data viewed in this tag is all formatted. The formatted data looks more intuitive, so Postman/Apifox also displays this option by default. For example, if you return an html page, it will be formatted into HTML format and displayed. For example, if you return json, it will also be formatted and displayed in json format.

  • Raw: translated into Chinese without processing, that is, raw data. Raw data is generally in the format of this article and has not been formatted. This option is generally available in packet capture tools.

  • Preview: Translated into Chinese is preview. This option is generally particularly effective for pages that return HTML. For example, after requesting Baidu to return the results, you can directly view the page after clicking this option, as shown below. At the same time, this option is the same as Preview in browser packet capture.
    Insert image description here

appendix

  1. Learn Apifox in 20 minutes

Guess you like

Origin blog.csdn.net/Blue_Pepsi_Cola/article/details/134984557