HTTP protocol [depth] --2019-08-09 12:11:34

table of Contents

Original: http://106.13.73.98/__/80/

HTTP is an abbreviation (Hyper Text Transfer Protocol) Hypertext Transfer Protocol.

HTTP is the result of the development of World Wide Web Consortium (World Wide Web Consortium) and the Internet Working Group IETF (Internet Engineering Task Force) collaboration, (they) finally issued a series of RFC.

RFC 1945 defines the HTTP / 1.0 version, most notably RFC 2616, RFC 2616 defines a widely used version today --HTTP 1.1

------->

HTTP protocol (Hyper Text Transfer Protocol) Hypertext Transfer Protocol is used for transmission from the WWW server Hypertext Transfer Protocol to the local browser.

It can make the browser more efficient, so that network traffic is reduced. Not only does it ensure that the computer correctly and quickly transfer hypertext document, the document also determines which part of the transmission, and which first part of the show (such as text prior to graphics) and so on.

@

HTTP response model
·
HTTP protocol is always initiated by the client request, the server sends the response back, as shown below:
Here Insert Picture Description
This limits the use of HTTP protocol, can not be achieved when the client did not initiate the request, the server pushes the message to the client.

HTTP workflow
·
一次HTTP操作称为一个事务course of their work can be divided into four steps:

  1. First, the client and the server needs to establish a connection. Just click on a hyperlink, HTTP work began.
  2. After the connection is established, the client sends a request to the server, the request means the format: Uniform Resource Identifier (URL), the protocol version
    is behind the MIME (statement text information) information includes a request modifiers, client information and possible content.
  3. Server upon request, to give the corresponding response information, the format of a status line comprising a protocol version number information, a success or error code
    back is a MIME information includes server information, entity information and possible content.
  4. The client receives the information returned by the server and the user on the display screen, and the client disconnects from the server through a browser.

·
If an error occurs in the course of more than a step, then an error message will be returned to the client by the display output.
For users, these processes are done by the HTTP themselves, users simply use the mouse to click and wait for information show on it.
***

HTTP request

HTTP request method Daquan
No. method description
1 GET Request page information specified, and returns the entity body.
2 HEAD Similar to get request, but the response is not returned in the specific content, for obtaining the header
3 POST Submitting data to the processing request specified resource (e.g., file submission form or upload). Data contained in the request body. POST request may result in a revision to establish and / or existing resources to new resources.
4 PUT Data transmitted from the client to the server designated to replace the contents of the document.
5 DELETE Requests the server to delete the specified page.
6 CONNECT HTTP / 1.1 protocol can be reserved for connection to the proxy server pipeline mode.
7 OPTIONS It allows the client to view server performance.
8 TRACE Echo request received by the server, mainly for testing or diagnosis.
9 PATCH Entity comprises a table, the table illustrates the differences in the contents of the original URI indicated.
10 MOVE The server will request the specified page to another web address.
11 COPY The request server to another copy of the page specified by the network address.
12 LINK Requests the server to establish a link relationship.
13 UNLINK Unlink relationship.
14 WRAPPED It allows the client sends a request through the package.
15 Extension-mothed Without modification of the protocol, another method may be increased.
The HTTP request includes

·
客户端连上服务器后,向服务器请求某个Web资源,称之为客户端向服务器发送了一个HTTP请求.
·
一个完整的HTTP请求包括的内容:一个请求行、若干消息头、实体内容.
·
Below:
Here Insert Picture Description

Details HTTP request - the request header

·
请求行中的GET称之为请求方式,请求方式有:POST、GET、HEAD、OPTIONS、DELETE、TRACE、PUT,常用的有: GET、 POST
·
用户如果没有设置,默认情况下浏览器向服务器发送的都是GET请求,例如在浏览器直接输地址访问,点超链接访问等都是GET,用户如想把请求方式改为POST,可通过更改表单的提交方式实现.
·
不管POST或GET,都用于向服务器请求某个WEB资源,这两种方式的区别主要表现在数据传递上:如果请求方式为GET方式,则可以在请求的URL地址后以?的形式带上交给服务器的数据,多个数据之间以&进行分隔,例如:GET /mail/1.html?name=abc&password=xyz HTTP/1.1
·
GET请求的特点:在URL地址后附带的参数是有限制的,其数据容量通常不能超过1K.
·
如果请求方式为POST方式,则可以在请求的实体内容中向服务器发送数据,Post方式的特点:传送的数据量无限制.

HTTP请求细节——消息头

·
Accept
声明浏览器支持的数据类型
·
Accept-Charset
声明浏览器支持的字符集
·
Accept-Encoding
声明浏览器支持的压缩格式
·
Accept-Language
声明浏览器的语言环境
·
Host
声明浏览器要访问那台主机
·
If-Modified-since
声明浏览器缓存数据的时间
·
Referer
声明客户机是哪个页面来的,用于防盗链
·
Connection
浏览器通过这个头告诉服务器,请求完后是断开链接还是保持链接
·
X-Requested-with: XMLHttpRequest
代表通过ajax方式进行访问
·
User-Agent
请求载体的身份标识,浏览器标识
·
以上为HTTP请求中的常用消息头,如下图:
Here Insert Picture Description
***

HTTP 响应

HTTP响应包括的内容

·
HTTP响应代表服务器向客户端回送的数据.
它包括:一个状态行、若干消息头、以及实体内容.
Here Insert Picture Description

HTTP响应细节——状态行

·
状态行格式:
HTTP/1.1 200 OK HTTP版本号 状态码 原因叙述<CRLF>
·
状态码用于表示服务器对请求的处理结果.
状态码是一个三位的十进制数,响应状态码分为5类.
Here Insert Picture Description
·
常见的HTTP状态码
·
100 客户端应继续发送请求
客户端应当继续发送请求,客户端应当继续发送请求的剩余部分.
或如果请求已经完成,忽略这个响应.
·
101 转换协议
在发送完这个响应的最后空行后,服务器将会切换到在Upgrade消息头中定义的那些协议.
只有在切换到新的协议更有好处的时候才应该采取类似的措施.
·
102 继续处理
由WebDAV(RFC 2518)扩展的状态码,代表请求将被继续执行.
·
200 请求成功
表示这条请求执行成功了.
处理方式:获得响应的内容,进行处理.
·
201 请求完成
表示这条请求执行完成了
结果是创建了新资源,新创建的资源的URL可在响应的实体中得到.
处理方式在爬虫中不会遇到.
·
202 请求被接受
请求被接受了,但处理尚未完成.
处理方式:阻塞等待.
·
204 服务器以实现请求
服务器已经实现了请求,但未返回新的信息.
如果客户端是用户代理,则无需为此更新自身的文档视图.
处理方式:丢弃.
·
300
该状态码不被HTTP/1.0的应用程序直接使用,只是作为3XX类型回应的默认解释,存在多个可用的被请求资源.
处理方式:若程序中能够处理,则进一步处理;若程序中不能够处理,则丢弃.
·
301 永久重定向
请求到的资源都会分配一个永久的URL,这样就可以在将来通过该URL来访问此资源.
处理方式:重定向到分配的URL,永久重定向.
·
302 临时重定向
请求到资源在一个不同的URL处临时保存.
处理方式:重定向到临时的URL,临时重定向.
·
304 请求的资源未更新
请求的资源未更新.
使用的是本地缓存文件(不会发送请求).
处理方式:丢弃.
·
400 非法请求
处理方式:丢弃.
·
401 未授权
处理方式:丢弃.
·
403 禁止
处理方式:丢弃.
·
404 没有找到
处理方式:丢弃.
·
500 服务器内部错误
服务器遇到了一个未曾预料的状况,导致它无法完成对请求的处理.
一般这个问题会在服务器端的源代码出现错误时出现.
即服务器问题,代码逻辑有问题.
·
501 服务器无法识别
服务器不支持当前请求需要的某个功能.
当服务器无法识别请求的方法时,将无法支持其对任何资源的请求.
·
502 错误网关
作为网关或代理工作的服务器尝试执行请求时,从上游服务器接收到无效的响应.

HTTP响应细节——常用响应头

·
Location
Server through the head, to tell the browser to jump to where
·
Server
declaration server model
·
Content-Encoding
server through the head, telling the browser, the compressed data format
·
Content-Length
statement server returns the length of the data
-
Content-Language
server through the head, telling the browser language environment
·
Content-Type
statement server returns the type of data
-
Refresh
server through the head, telling the browser periodically refresh
·
Content-Disposition
server through the head, telling the browser to download the open the data
-
Transfer-Encoding
server through the head, telling the browser data is blocking the way loopback the
·
Expires: -1
control the browser not to cache
·
Cache-Control: no-cache
· more: http: //tools.jb51.net/table/http_header
Pragma: no-cache


Original: http://106.13.73.98/__/80/

Guess you like

Origin www.cnblogs.com/gqy02/p/11326450.html