Theory of http communication in Android

一.HTTP

 

HTTP is a hypertext transfer protocol, which is oriented to the application layer protocol. The object of transmission is a file.
One Http operation is a transaction
1: The client and the server establish a connection, click the link to start work
2: The client sends a request to the server in the format of URL, Protocol version number, followed by MIME information
3: After the server receives the request, it will give response information in the format of a status line, including the protocol version number, a success or error code, followed by MIME information (404 error code is unable to respond )
4: The client street server's response information, and then disconnect the
HTTP protocol is a stateless protocol
URL (UniformResourceLocator) for the web page address. It consists of three parts: the first part is the protocol (https is an encryption protocol), the second part is the IP address (usually the domain name indicates the IP address) (sometimes including the port number), and the third part is the specific address of the host resource, such as directory and File name

TCP/IP three-way handshake
SYN is the handshake information (synchronous) used in the TCP/IP connection. When a normal TCP network connection is established between the client and the server, the client first sends a SYN message, and the server uses SYN and ACK. The response indicates that the information has been received, and finally the client confirms the response with ACK information, so that a reliable TCP connection is established between the client and the server. ACK
(Acknowledgement) is the confirmation character, indicating that the information has been received . OK, I want to establish a connection with you (send SYN request to connect) Server: Hello, I have received the information and are ready to connect, and I also want to establish a connection with you (send ACK to indicate connection, and send SYN to indicate connection idea ) client: thanks, I've received your connection idea, and I'm ready to connect (send ACK back to indicate that it can connect)




The whole process is that both parties need to send the connection idea and confirm the connection information to each other

http request header information:
Request URL: the requested address
Request Method: request method
Status Code: request status
Accept: acceptable file format
Accept-Encoding: acceptable Coding
Accept-Language: acceptable language
Connection: connection method
Host: host address
http response form:
200 OK //The client request is successful
400 Bad Request //The client request has a syntax error and cannot be understood by the server
401 Unauthorized // The request is unauthorized, this status code must be used in conjunction with the WWW-Authenticate header.
403 Forbidden // The server received the request, but refused to serve

 

2. The SI reference model divides the entire network communication function into seven levels:


由低到高分别是物理层PH、数据链路层DL、网络层N、传输层T、会话层S、表示层P、应用层A
http协议属于应用层
每层直接为其上层提供服务,并且所有层次都互相支持。四到其层负责互操作性;一到三层用于创造两个网络设备间的物理连接
物理层和数据链路层:将比特流转换成电流信息,在物理设备电流设备转化
网络层:IP协议,规划网络ip地址
传输层:降底层信息通过nava协议传输,对应tcp、udp等协议
会话层:建立连接
表示层:在两个不同编码方式下进行数据转化和编码的加密解密操作
应用层:http访问层,应用请求协议
提出tcp/ip四层协议

 

三.HTTP1.0和HTTP1.1的区别

 

http/1.0和1.1区别
HTTP/1.0每次请求都需要建立新的TCP连接,连接不能复用。
HTTP/1.1新的请求可以在上次请求建立的TCP连接之上发送,连接可以复用。优点是减少重复进行TCP三次握手的开销,提高效率。
HTTP1.1在Request消息头里头多了一个Host域,HTTP1.0则没有这个域。Host:www.w3.orghttp/1.0和1.1区别
HTTP/1.0每次请求都需要建立新的TCP连接,连接不能复用。
HTTP/1.1新的请求可以在上次请求建立的TCP连接之上发送,连接可以复用。优点是减少重复进行TCP三次握手的开销,提高效率。
HTTP1.1在Request消息头里头多了一个Host域,HTTP1.0则没有这个域。Host:www.w3.org
HTTP1.1增加了OPTIONS,PUT,DELETE,TRACE,CONNECT这些Request方法
HTTP1.1增加了OPTIONS,PUT,DELETE,TRACE,CONNECT这些Request方法

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326802730&siteId=291194637