Learn http (ii) HTTP architecture and basics from scratch

Source: Internet
Author: User

HTTP Architecture and Basics

In this article, we mainly introduce the http\1.1 version

Request messages and response messages

Request message

The request message is sent by the client, in the form of:

Request method Request URI Protocol version optional request header field and content entity, for example:

Post  /index.html HTTP/1.1* Host是请求首部字段,代表服务器主机Host: www.hukaihe.cnConnection: keep-aliveContent-Type: application/x-www-form-urlencodedContent-Length:16nickName=AgentKyle&age=21

It can also be written in the following form:

GET http://www.hukaihe.cn/index.html HTTP/1.1*不使用Host首部字段... ...

If you are not accessing a specific resource but initiating access to the server itself, you can use "*" instead of the URI

Response message

Response message by: HTTP version number status Code reason statement Optional Response header field entity body

For example:

HTTP/1.1 200 okDate: Tue, 10 Jul 2017 03 18 14:45:15 GMTContent-Length: 686Content-Type:text/html* 资源主体的实体(entity body)

Features of HTTP

Client and server side

The HTTP protocol specifies that the request is made by the client and the last server-side response should be requested and returned. That is, we must first establish communication from the server side.

Sometimes, as a matter of fact, the roles of both computers as both client and server are likely to be interchangeable, but in the case of a communication route, the roles of the server side and the client are determined. The HTTP protocol can clearly distinguish which end is the client and which is the server side.

State

HTTP is a stateless (stateless) protocol. This is designed to handle a large number of transactions faster, ensure the scalability of the Protocol, and reduce the CPU and memory resources consumed by the server.

You can use cookie technology to manage the status of HTTP. The cookie controls the state of the client by writing cookie information to the request and the corresponding message. The cookie notifies the client to save cookie information based on a header field information in a response message sent from the server, called Set-cookie. When the next client sends a request to the server, the client automatically adds the cookie value to the request message and sends it out. After the server-side discovery of the cookie sent by the client, it checks exactly which client sent the connection request, compares the records on the server, and finally gets the user's status information.

Persistent connection and pipelining

When we visit an HTML page with many illustrations, there are many HTTP requests to access the images. If you need to repeatedly establish and disconnect TCP connections for each request, this can cause a lot of additional performance overhead.

Thus, in HTTP1.1, all connections default to a persistent connection (keep-alive) policy, which is to keep the TCP connection state if no connection is explicitly made at either end. This reduces the additional overhead of TCP connections and the load on the server, allowing HTTP requests and responses to end early and speed up the display of Web pages.

and pipeline technology on the basis of persistent connection, so that multiple requests can be sent in parallel, no blocking phenomenon. (You don't have to wait for a request to return a response to send another request), which significantly increases the speed of the request.


The melody of the Bible
Links: https://www.imooc.com/article/17058
Source: MU-Class Network
This article original published in Mu class network, reproduced please indicate the source, thank you for your cooperation!

Learn http (ii) HTTP architecture and basics from scratch

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.