a basic concept
HTTP (Hypertext Transfer Protocol) is a stateless, application-level protocol based on the request-response pattern, often based on TCP connection.
two HTTP requests
The HTTP request consists of three parts: the request line, the message header, the request body
1 Request Lines
<method> <uri> <version>
Method (Request):
Get: Request for the resource identified by Request-uri
Post: Append new data to the resource identified by Request-uri
HEAD request Gets the response message header for the resource identified by Request-uri
PUT Request server stores a resource and uses Request-uri as its identity
Delete Request server deletes the resource identified by the Request-uri
URI and URL
URI: Uniform Resource Identifier. A simple string that identifies a resource in a uniform (standardized) way.
URL: Uniform Resource Locator. A concise representation of the location of resources and access methods available from the Internet is the address of standard resources on the Internet. Each file on the Internet has a unique URL that contains information that indicates the location of the file and how the browser should handle it.
The general format is:http://host[":" Port][abs_path]
Example: http://www.google.com:80/index.html
The difference between a URI and a URL: A URI defines a resource, and a URL defines not only that resource, but also how to find it. For example, on a server, the absolute address (absolute path) to a folder/Web page is the URI.
<version>:http 1.0 and HTTP 1.1
Version differences:
To establish a connection:
http/1.0 each request requires a new TCP connection and the connection cannot be reused. http/1.1 a new request can be sent on top of the last TCP connection that was requested, and the connection can be reused.
The advantage is to reduce the overhead of repeating the TCP three handshake and increase the efficiency.
Note: In the same TCP connection, the new request needs to wait until the last request receives a response before it can be sent.
Some of the other differences will be added later.
2 Request Header
The only current concern is the host header, which is required in version 1.1 and not required in version 1.0.
Terminates the list of headers with an empty line of text.
Three HTTP response
The HTTP response is also made up of three parts: status line, message header, response body
1 status Line
<version> <status code> <status message>
Status code:
The status code consists of three digits, the first number defines the category of the response, and there are five possible values:
1XX: Indication information--Indicates that the request has been received and continues processing
2XX: Success-Indicates that the request has been successfully received, understood, accepted
3XX: Redirect--further action is required to complete the request
4XX: Client Error--Request syntax error or request not implemented
5XX: Server-side error-the server failed to implement a legitimate request
Common status codes, status descriptions, descriptions:
$ OK//client request succeeded
Bad Request//client requests have syntax errors and cannot be understood by the server
401 Unauthorized//request unauthorized, this status code must be used with the Www-authenticate header field
403 Forbidden//server receives request, but refuses to provide service
404 Not Found//request resource not present, eg: Wrong URL entered
Internal Server error//server unexpected errors
503 Server Unavailable//The server is currently unable to process client requests and may return to normal after a period of time
Example: http/1.1 OK
2 message Header
The main focus is on two more important
Content-type: Tells the client the MIME type of the content in the response topic.
Content-length: Used to refer to the byte size of the response body.
The response header is terminated with a blank line of text, followed by the response body, and the requested content is included in the response body.
HTTP protocol Basics