(Rpm) "illustrates HTTP" - Simple HTTP protocol

 

https://www.jianshu.com/p/d3268aa4ae84

 

Foreword

Currently, the front end must understand the essential knowledge of HTTP, and he himself was learning, I was mainly by reading "graphic HTTP" learning, here are some of their own study notes. This chapter introduces the HTTP protocol.

HTTP is a protocol does not save state

HTTP is a protocol does not save the state of
HTTP is a stateless protocol. HTTP protocol itself does not request and the communication status between the response stored. That is the level of HTTP, the protocol for sending off requests and responses do not deal with persistence.

 
 

 

Why should I do?
This is for faster processing a large number of transactions, to ensure that the agreement scalability. HTTP and deliberately designed to be so simple.

So I want to save the state, then how to do?
HTTP / 1.1 put forward the corresponding solutions, although no agreement is HTTP1.1 state, but the introduction of Cookie technology. With the re-use HTTP Cookie communication, you can manage the state. I will summarize back to Cookie.

HTTP method

HTTP methods are there? And what they use

  • GET method. Access to resources. To request access to a resource identified by URI cup. After a specified resource server parses the contents of the response returned.
  • POST method. Transmission content entity. Although the GET method can also be used to transfer the contents of entity, but we generally do not how to do it. The main purpose is not to obtain POST body content of the response.


     
     
  • PUT method. Transfer files. I wanted to request files on the FTP protocol to upload the same content requirements contained in the file request message entity, and then save the request URI specified location. But given the PUT method HTTP1.1 themselves without a verification mechanism, anyone can upload files, there are security problems, so generally do not use the website in this way. When combined with Web application authentication mechanism, or REST architecture design uses a standard similar Web site, it may open a PUT method.


     
     
  • HEAD方法。获取报文首部 。HEAD方法和GET方法一样,只是不返回报文的主体部分。用于确认URI的有效性以及资源更新的日期时间等。
  • DELETE方法。删除文件。与PUT方法相反,按照请求的URI删除指定的资源。
  • OPTIONS方法用来查询针对请求的URI指定的资源支持的方法。
 
 

 
 
  • TRACE。追踪路径。让web服务器将之前的请求通信环回给客户端的方法。发送请求的时候,在Max-Forwards首部字段中加入数值,每经过一个服务器端该数字就减一,当数值刚好减到0的时候,就停止传输,最后收到请求的服务器返回的200OK的响应。

但是TRACE方法本来就不怎么常用,而且它容易引发XST(跨站追踪),通常就更加不会用到了。

 
 

CONNECT方法。要求隧道协议连接代理
CONNECT方法要求在与代理服务器通信的时候建立隧道,实现用隧道协议进行TCP通信。主要使用SSL(secure sockets layer,安全套接层)和TLS(Transport Layer Security,传输层安全)协议把通信内容加密后经过网络隧道传输。
CONNECT方法的格式如下:
CONNECT代理服务器名:端口号 HTTP版本


 
 

最后,我们要知道,方法的作用在于,可以指定请求的资源按照期望产生某种行为。而且方法的名称分大小写之分,记得使用大写。

 
方法一览图

持久连接节省流量

在一开始的HTTP协议中,每进行一次HTTP 通信就断开一次TCP连接。


 
 

在请求一个很多资源的HTML页面的时候,每次连接都会造成无所谓的TCP连接的建立和断开,增加了通信量的开销。

什么是持久连接
持久连接也被称为HTTP keep alive或者HTTP connection reuse。它的特点是,只要任意一端没有明确提出断开连接,则保持TCP连接状态。

 
 

 

这样做的好处:

  • 减少了TCP连接重复建立和断开的时间开销
  • It reduces the load on the server side

In HTTP / 1.1, all the connections are persistent by default connection, but the HTTP / 1.0 the ratio is not standardized. Although there are some non-standard part of the service by the end of the means to achieve a lasting connection, but the server may not be able to support a persistent connection.

What is pipelined
to wait and after receiving the response before sending the request to be sent after a request before. After pipelining technology appears, it can be sent without waiting for the next request.

Pipelined benefits

  • You can do simultaneously send multiple requests in parallel, one after another without waiting for a response.


     
     

Cookie technology

Works of Cookie: Cookie will be based on the response message sent from the server in a known set-Cookie header field, the notification client to save Cookie. When a client sends a request next time go down to the server, the client will automatically join the Cookie value in the request messages to be sent out.

Upon receipt of the service termination Cookie, we will check whether it is sent by the client from which the (mainly by comparing the service end of recording), before finally get status information.

  • The first time the request (that is, not Cookie)


     
     
  • When the second request


     
     

The above two request and response request message is as follows:


 
 

You can also look at the specific understanding of the session and session_id



Author: GpingFeng
link: https: //www.jianshu.com/p/d3268aa4ae84
Source: Jane book
Jane book copyright reserved by the authors, are reproduced in any form, please contact the author to obtain authorization and indicate the source.
 
 
 

Guess you like

Origin www.cnblogs.com/stableboy/p/11226320.html