Http is called HyperText Transfer Protocol. It guides the browser to communicate with the server. The normal communication process is as follows:

The browser initiates the request –> the server receives the request on port 80 –> the server returns a content response –> the browser downloads the content of the response

There are two ways to initiate a request. One is to directly enter the url or perform an operation in the browser. The other is to use the command line curl command to initiate a request.

1, use the browser to enter the URL to initiate a request, that is, the URL, a URL generally contains the following parts:

Protocol Domain name Port path query parameter anchor

For example: www.baidu.com/s?wd=hello&…

HTTPS is the protocol name, www.baidu.com is the domain name, /s is the path, which does not mean that the corresponding file exists,? Wd =hello&rsv_spt=1 is the query parameter, and #5 is the anchor point.

View the request and response content in the browser:

Open Chrome, choose More Tools > Developer Tools in the upper right corner of Settings, you will see this window, click Network



Refreshing a web page will result in many more such requests



Click the first one to enter the following page:



Click View Source to see the corresponding content, where Response Headers represents the Response content and Request Headers represents the Request content.

2, using curl:

To curl: to curl

The options have some common abbreviations as follows: -a/–append Appends to the destination file when uploading the file

-a /–user-agent <string> Sets the user agent to send to the server

-d/–data <data> Transmits data in Http POST mode

-d /–dump-header <file> Writes header information to the file

-e/– Referer source url

-f/–fail No HTTP error is displayed when the connection fails

-f /–form <name=content> Emulated HTTP form submission data

-g /–get Sends data in get mode

-h /–header <line> Custom header information is passed to the server

-i/–include Includes the protocol header

-i /–head Displays only the request header information

-j/–junk-session-cookies Ignore session cookies when reading files

-k/–insecure Allows not using certificates to SSL sites

-k /–config Reads the specified configuration file

-l/–list-only Lists the file names in the FTP directory

-m/–max-time

Sets the maximum transmission time

-o/–output Writes output to the file

-o /–remote-name Writes the output to the file and keeps the name of the remote file

-p/–proxytunnel Uses HTTP proxy

-s/–silent Mode. It doesn’t output anything

-u/–user

Sets the user name and password of the server
[:password]>

-v/–version Displays version information

-x /–request Specifies what command

Command request instance:

curl -s -v  -H “hello” –“https://www.baidu.com”

Send a request to Baidu with a hello header.

As you can see, a number of things are returned to us, including the following:



The request contains a maximum of 4 parts and a minimum of 3 parts. The fourth part can be empty:

Part I: Verb path protocol/versioning

Verb (request GET/POST/PUT/PATCH/DELETE)

Get: requests information about the specified page and returns data

Post: Submits data to a specified resource for processing requests

Put: Data sent from the client to the server completely replaces the specified document content

Patch: Part of the data transferred from the client to the server replaces the specified document content

Delete: requests the server to Delete the specified content

Path: The path in the link from which the request was initiated, which can be empty but starts with/by default, and contains query parameters but no anchor points

Protocol: The protocol used, such as HTTPS, FTP, etc

Version number: indicates the protocol version number

Part 2 Format: Key :value



Part 3: Always a Carriage Return (/n)

Part 4: Generally data to be uploaded, and if there is a Content-Type in Part 2, the value of the content-Type indicates the format of the content in Part 4.

If you do not write the request, the default is Get, or you can change it to Post to send data to the corresponding link:

curl -X POST -d “1234” -s -v -H “hello” –“https://www.baidu.com”

The resulting request reads:



The response content obtained:



The format of the response also consists of four parts:

Part ONE: Protocol/Version status code status description

Status code:

200: The request is successfully received. 202: the server receives the request successfully. 301: The requested resource is permanently moved to the new location

302: The requested resource is temporarily inaccessible and can be accessed later

404: Request failed. The requested resource was not found on the server

500: Server error 502: Invalid response from upstream server when a server working as a gateway or proxy tries to execute a request

The format of Part 2: key:value. Similarly, Content-Type specifies the format of Part 4

Part 3: A Carriage Return (/n)

Part four: Content to download

That’s a brief overview of HTTP requests and responses.