HTTP Protocol [Detailed] - Basic Concepts

An HTTP request consists of three parts: the request line, the message header, and the request body

HTTP (Hypertext Transfer Protocol) is a stateless, application-layer protocol based on request and response mode. Web development is a web application built on the HTTP protocol.

1. What are the commonly used HTTP methods?
GET: 
Used to request access to a resource identified by a URI (Uniform Resource Identifier), which can be passed to the server through the URL.
POST: used to transmit information to the server, the main function is similar to the GET method, but the POST method is generally recommended.
PUT:  Transfer a file, the message body contains the file content and saves it to the corresponding URI location.
HEAD:  Get the header of the message, similar to the GET method, except that it does not return the body of the message. It is generally used to verify whether the URI is valid.
DELETE: Deletes a file, in contrast to the PUT method, deletes the file at the corresponding URI location.
OPTIONS: Query the HTTP methods supported by the corresponding URI.


2. The difference between the GET method and the POST method
Difference 1:

get focuses on obtaining resources from the server, and post focuses on sending data to the server;
difference 2:
get transmits data through a URL request, in the form of field = value, Put it after the URL, and use "?" to connect, and use "&" to connect multiple request data, such as http://127.0.0.1/Test/login.action?name=admin&password=admin, this process is visible to the user;
The post transmits data through Http's post mechanism, encapsulates fields and corresponding values ​​in the request entity and sends them to the server. This process is invisible to the user;
difference three:
The amount of data transmitted by Get is small, because it is limited by the length of the URL, but the efficiency is high;
Post can transmit a large amount of data, so only the Post method can be used when uploading files;
Difference 4:
Get is not safe, because the URL is visible, it may be It will leak private information, such as passwords;
post is more secure than get;
difference five:
get mode can only support ASCII characters, and the Chinese characters sent to the server may be garbled.
post supports standard character sets and can correctly pass Chinese characters.


3. HTTP request message and response message format

The request message contains three parts:
a. Request line: contains request method, URI, HTTP version information
b, request header field
c, request content entity
The response message contains three parts:
a. Status line: contains HTTP version, status code, Reason phrase
b for status code, response header field
c, response content entity

4, common HTTP corresponding status codes

Returned status
1xx: Indication information--indicates that the request has been received, continue processing
2xx: Success--indicates that the request has been successfully received, understood, accepted
3xx: Redirect-- Further operations must be performed to complete the request
4xx: Client Error -- The request has a syntax error or the request cannot be fulfilled
5xx: Server Side Error -- The server failed to fulfill a legitimate request


200:
请求被正常处理
204:请求被受理但没有资源可以返回
206:客户端只是请求资源的一部分,服务器只对请求的部分资源执行GET方法,相应报文中通过Content-Range指定范围的资源。
301:永久性重定向
302:临时重定向
303:302状态码有相似功能,只是它希望客户端在请求一个URI的时候,能通过GET方法重定向到另一个URI上
304:发送附带条件的请求时,条件不满足时返回,与重定向无关
307:临时重定向,与302类似,只是强制要求使用POST方法
400:请求报文语法有误,服务器无法识别
401:请求需要认证
403:请求的对应资源禁止被访问
404:服务器无法找到对应资源
500:服务器内部错误
503:服务器正忙




5、HTTP1.1版本新特性
a、默认持久连接节省通信量,只要客户端服务端任意一端没有明确提出断开TCP连接,就一直保持连接,可以发送多次HTTP请求

b、管线化,客户端可以同时发出多个HTTP请求,而不用一个个等待响应

c、断点续传原理



6、常见HTTP首部字段
a、通用首部字段
(请求报文与响应报文都会使用的首部字段)
Date:创建报文时间
Connection:连接的管理
Cache-Control:缓存的控制
Transfer-Encoding:报文主体的传输编码方式
b、请求首部字段(请求报文会使用的首部字段)
Host:请求资源所在服务器
Accept:可处理的媒体类型
Accept-Charset:可接收的字符集
Accept-Encoding:可接受的内容编码
Accept-Language:可接受的自然语言
c、响应首部字段(响应报文会使用的首部字段)
Accept-Ranges:可接受的字节范围
Location:令客户端重新定向到的URI
Server:HTTP服务器的安装信息
d、实体首部字段(请求报文与响应报文的的实体部分使用的首部字段)
Allow:资源可支持的HTTP方法
Content-Type:实体主类的类型
Content-Encoding:实体主体适用的编码方式
Content-Language:实体主体的自然语言
Content-Length:实体主体的的字节数
Content-Range:实体主体的位置范围,一般用于发出部分请求时使用


7、HTTP的缺点与HTTPS
a、通信使用明文不加密,内容可能被窃听
b、不验证通信方身份,可能遭到伪装
c、无法验证报文完整性,可能被篡改

HTTPS就是HTTP加上加密处理(一般是SSL安全通信线路)+认证+完整性保护

 

8、HTTP优化

利用负载均衡优化和加速HTTP应用

利用HTTP Cache来优化网站


参考链接

https://www.cnblogs.com/lingyejun/p/7148756.html?utm_source=itdadao&utm_medium=referral

https://www.cnblogs.com/sunny-sl/p/6529830.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325372794&siteId=291194637