iOS~网络基础~Http & SSL & Ht

2019-01-15  本文已影响27人  派大星的博客

Http 协议的格式

pasted-image.png

Request message

The request message consists of the following:

The request line and other header fields must each end with <CR><LF> (that is, a carriage return character followed by a line feed character). The empty line must consist of only <CR><LF> and no other whitespace.[15] In the HTTP/1.1 protocol, all header fields except Host are optional.

A request line containing only the path name is accepted by servers to maintain compatibility with HTTP clients before the HTTP/1.0 specification in RFC 1945.[16]


pasted-image-2.png

Response message

The response message consists of the following:

The status line and other header fields must all end with <CR><LF>. The empty line must consist of only <CR><LF> and no other whitespace.[15] This strict requirement for <CR><LF> is relaxed somewhat within message bodies for consistent use of other system linebreaks such as <CR> or <LF> alone.[33]

pasted-image-3.png
QQ20180130-154706@2x.png

HTTP/1.0

HTTP/1.1

HTTP/2


HTTP连接

HTTP协议即超文本传送协议(Hypertext Transfer Protocol ),是Web联网的基础,也是手机联网常用的协议之一,HTTP协议是建立在TCP协议之上的一种应用。
HTTP连接最显著的特点是客户端发送的每次请求都需要服务器回送响应,在请求结束后,会主动释放连接。从建立连接到关闭连接的过程称为“一次连接”。
1)在HTTP 1.0中,客户端的每次请求都要求建立一次单独的连接,在处理完本次请求后,就自动释放连接。

2)在HTTP 1.1中则可以在一次连接中处理多个请求,并且多个请求可以重叠进行,不需要等待一个请求结束后再发送下一个请求。

由于HTTP在每次请求结束后都会主动释放连接,因此HTTP连接是一种“短连接”,要保持客户端程序的在线状态,需要不断地向服务器发起连接请求。通常 的做法是即时不需要获得任何数据,客户端也保持每隔一段固定的时间向服务器发送一次“保持连接”的请求,服务器在收到该请求后对客户端进行回复,表明知道 客户端“在线”。若服务器长时间无法收到客户端的请求,则认为客户端“下线”,若客户端长时间无法收到服务器的回复,则认为网络已经断开。


HTTP header fields

Headers can be grouped according to their contexts:

屏幕快照 2019-01-22 上午11.34.45.png 屏幕快照 2019-01-22 上午11.29.54.png 屏幕快照 2019-01-22 上午11.30.14.png

断点续传相关:

屏幕快照 2019-01-22 上午11.32.34.png 屏幕快照 2019-01-22 上午11.32.41.png

Http 和 Https 对比

Http 和 Https 对比.png

Https 就是在会话层加入了SSL(Secure Sockets Layer)协议的Http协议

SSL Handshake

屏幕快照 2019-01-22 上午11.49.17.png

1、 Browser connects to a web server (website) secured with SSL (https). Browser requests that the server identify itself.

2、Server sends a copy of its SSL Certificate, including the server’s public key.

3、Browser checks the certificate root against a list of trusted CAs and that the certificate is unexpired, unrevoked, and that its common name is valid for the website that it is connecting to. If the browser trusts the certificate, it creates, encrypts, and sends back a symmetric session key using the server’s public key.

4、Server decrypts the symmetric session key using its private key and sends back an acknowledgement encrypted with the session key to start the encrypted session.

5、Server and Browser now encrypt all transmitted data with the session key.


上一篇下一篇

猜你喜欢

热点阅读