Beginner’s Guide to API Testing – Basics of HTTP Protocol

1、URL:Uniform Resource Locator

2Components of URL:

<protocol>://[<user>:<password>]@<host>:<port>/<path>[:<params>]?<query>#<fragment>

protocol:The protocol used for access, such as: http, https, ftp

host:The hostname, which can be an IP address or a domain name, for example: 192.168.10.12, www.baidu.com.

port:The port of the host when accessed. The default port for HTTP protocol is 80 and can be omitted.

path:We can locate the host through host:port, but since there are many files on the host, the path can be used to locate a specific file. For example: https://baike.baidu.com/item/软件测试/327953

params:Parameters passed to the server, generally rare.

query:The query string, used to query content from the server. For example: www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95

fragment:A fragment, which can divide a webpage into different sections. If you want to directly reach a specific location after accessing the webpage, you can set it in this part.

Example:

(1)Sina Stars:

http://slide.ent.sina.com.cn/star/slide_4_704_336821.html#p=1

(2)Baidu Search:

https://www.baidu.com/s?rtt=1&bsst=1&cl=2&tn=news&rsv_dl=ns_pc&word=%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95

3HTTP Protocol:

HTTP (Hyper Text Transfer Protocol):

It is a stateless, application-layer protocol based on a request-response model that connects using TCP, with a default port of 80.

4HTTP Workflow:

(1)The client establishes a TCP connection with the server.

(2)The client sends a request to the server.

(3)The server receives the client’s request and returns a response based on the request.

(4)The client receives the server’s response, parses the content for frontend display; then the client disconnects from the server.

5Characteristics of HTTP:

(1)Supports client/server model.

(2)Simple and fast: When the client requests a service from the server, it only needs to send the request method and path.

(3)Flexible: HTTP allows the transmission of any type of data object.

(4)Stateless: If subsequent processing requires previous information, it must be retransmitted.

a、Disadvantage: It may lead to an increase in data volume transmitted per connection.

b、Advantage: If the server does not require prior information, responses are faster, reducing CPU and memory consumption on the server.

c、Introduction of cookie and session mechanisms: Cookies record information on the client side to determine user identity, while sessions record information on the server side to determine user identity.

(5)Connectionless: Limits each connection to handle only one request. After the server processes the request and receives the response, it disconnects.

a、Disadvantage: Each request requires establishing and disconnecting a TCP connection, increasing communication overhead.

b、Advantage: This method can save transmission time.

c、Subsequent introduction of persistent connections (HTTP keep-alive): Multiple data can be sent continuously over a single TCP connection without disconnecting, reducing the number of TCP connection establishments; generally, the server sets a keep-alive timeout (the connection will close after this time if it exceeds after transmission) and a maximum number of connections (when the maximum number is reached, new requests will initiate connections, and previous connections will close if not timed out).

6Disadvantages of HTTP:

(1)Eavesdropping: HTTP communication uses plaintext, and there are no encryption measures during transmission, which may be eavesdropped.

(2)Impersonation: During transmission, the identity of the communication party is not verified, which may lead to impersonation.

(3)Tampering: HTTP only parses the message but does not perform complete verification, so it cannot verify the integrity of the message, which may be tampered with.

If you like my article, please follow me, and feel free to ask questions!~

Leave a Comment