Basic principles and practical tutorials of API interface automated testing

Table of contents

Commonly used API interface protocol introduction

Introduction to Http protocol interface request

HTTPS protocol

SMTP protocol

SNMP protocol

FTP protocol

Basic principles of API interface automated testing


Commonly used API interface protocol introduction

HTTP protocol 

Hypertext Transfer Protocol

It is a transmission protocol used to transmit hypertext on the Internet. It runs on the TCP/IP protocol family. It can make browsers more efficient and reduce network transmission.

In addition to including HTML files, any server also has an HTTP resident program for responding to user requests.

The browser is an HTTP client and sends a request to the server. When a start file is entered in the browser or a hyperlink is clicked, the browser sends an HTTP request to the server, and the request is sent to the URL specified by the IP address. The resident program receives the request and returns the requested file after performing the necessary operations.

     API interface testing video tutorial: 1 lesson to understand the principle of front-end and back-end interaction requests for automated testing of API icon-default.png?t=N3I4interfaces

         

 

Introduction to Http protocol interface request

An http request message consists of four parts: request line, message header, blank line, and request body;

1. Request line

The request line consists of the request method field, the URL field and the HTTP protocol version field, which are separated by spaces, for example: GET /index.html HTTP/1.1

The request methods of the HTTP protocol include GET, POST, HEAD, PUT, DELETE, OPTIONS, TRACE, and CONNECT. Here are the most commonly used GET and POST methods;

GET: When the client wants to read documents from the server, use the GET method. The GET method requires the server to place the resource located by the URL in the data part of the response message and send it back to the client. When using the GET method, the request parameters and corresponding values ​​are appended to the URL, and a question mark ("?") is used to represent the end of the URL and the beginning of the request parameters. The length of the passed parameters is limited, for example: /index.jsp?id=100&op =bind

POST: When the client provides more information to the server, use the POST method. The POST method encapsulates the request parameters in the HTTP request data in the form of key/value, which can transfer a large amount of data and can be used to transfer files.

2. Message header

The request header consists of key/value key-value pairs, one pair per line, and the key and value are separated by a colon ":". The request header notifies the server of the request information about the client. Typical request headers:

User-Agent: The type of browser that made the request

Accept: A list of content types recognized by the client

Host: The requested host name, allowing multiple domain names to be in the same IP address, that is, a virtual host    

3. Empty line

After the last request header is a blank line, sending a carriage return and line feed to notify the server that the request header is over. Blank lines are necessary for a complete http request, otherwise the server will task that the data of this request has not been fully sent to the server and is in a waiting state

4. Request body

Request data is not used in GET method but in POST. The POST method is suitable for occasions where the client needs to fill in the form. The most commonly used request headers related to the requested data are Content-Type and Content-Length

Http protocol interface return status code introduction

Common status codes, status descriptions, instructions  :

200 OK //The client request is successful 

400 Bad Request //The client request has a grammatical error and cannot be understood by the server 

401 Unauthorized //The request is unauthorized, this status code must be used with the WWW-Authenticate header field  

403 Forbidden //The server received the request, but refused to provide the service 

404 Not Found //The requested resource does not exist, eg: wrong URL is entered 

500 Internal Server Error //An unexpected error occurred on the server 

503 Server Unavailable //The server is currently unable to process the client's request, and it may return to normal after a period of time

Http Protocol Interface Entity Header Introduction

Both request and response messages can carry an entity. An entity consists of an entity header field and an entity body, but it does not mean that the entity header field and the entity body must be sent together, and only the entity header field can be sent. The entity header defines meta information about the entity body (eg: presence or absence of an entity body) and the resource identified by the request. 

The Content-Type entity header field term indicates the media type of the entity body sent to the recipient

如:Content-Type:text/html;charset=ISO-8859-1 ,

Content-Type:application/json; 

Content-Type:application/soap+xml; 

Content-Type:application/x-www-form-urlencoded

HTTPS protocol

Hypertext Transfer Security Protocol

It was developed by Netscape and built into its browser to perform compression and decompression operations on data and return the results sent back over the network.

HTTPS actually uses Netscape's Full Sockets Layer (SSL) as a sublayer of the HTTP application layer. (HTTPS uses port 443, instead of using port 80 to communicate with TCP/IP like HTTP.) SSL uses a 40-bit keyword as the RC4 stream encryption algorithm, which is suitable for the encryption of business information. HTTPS and SSL supports the use of X.509 digital certificates, allowing users to confirm who the sender is if desired.

SOAP protocol

Simple Object Access Protocol

It is a protocol specification for exchanging data. It is a lightweight, simple, XML-based (a subset of standard general markup language) protocol. It is designed to exchange structured and solidified data on the WEB. Information, SOAP uses a combination of XML-based data structures and Hypertext Transfer Protocol (HTTP) to define a standard method to use distributed objects in various operating environments on the Internet.

1 lesson to understand the principle of front-end and back-end interaction requests for automated testing of API icon-default.png?t=N3I4interfaces

SMTP protocol

Simple Mail Transfer Protocol

It is a set of rules for transmitting mail from the source address to the destination address, and it is a protocol used to control the transfer mode of letters.

The TCP port number used by SMTP is 25. The receiving end waits for the E-mail from the sending end on TCP port 25, and the sending end sends a connection request to the receiving end (server). Release the connection after the transfer is complete.

SNMP protocol

Simple Network Management Protocol

It is a standard protocol specially designed for managing network nodes (servers, workstations, routers, switches and HUBS, etc.) in IP networks.

SNMP consists of a set of network management standards, including an application layer protocol, a database schema, and a set of resource objects. The protocol supports network management systems to monitor devices connected to the network for any conditions of administrative concern.

FTP protocol

file transfer protocol

It is a standard protocol and the easiest way to exchange files between computers and networks. Like HTTP and SMTP for sending displayable files, FTP is also an application protocol standard using the TCP/IP protocol.

FTP is usually used to upload web pages from creators to servers for human use, and uploading files from servers is also a very common way of use. As a user, you can use FTP with a very simple DOS interface, or you can use FTP with a graphical interface provided by a third party to update (delete, rename, move and copy) files on the server.

Basic principles of automated testing of API  interfaces

Basic principles of automated testing based on HTTP protocol

1. Simulate request url and message, prepare test data

2. Simulate client to send HTTP request

3. Simulate the client receiving the return message from the server

4. Verify that the returned results meet expectations

1 lesson to understand the principle of front-end and back-end interaction requests for automated testing of API icon-default.png?t=N3I4interfaces

 

Guess you like

Origin blog.csdn.net/MXB_1220/article/details/130466531