HTTP Brief

HTTP profile:

  1, Hyper Text Transfer Protocol ( Hypertext Transfer Protocol ), it is mainly used for communication between the Web browser and a Web server

  2, which is based on TCP / IP communications protocol to transfer data

  3, the main features:

    ① simple and fast: client service request to the server, instead of sending the request method and path

    ② Flexible: allow the transmission of any data object type, a Content-Type Marker Type

    ③ no connection: restriction process only one request per connection

    ④ stateless: server does not retain any data requests between two

    ⑤ Support B / S (Browser / Server) and C / S (Client / Server) mode

 

URL:

  1、格式:protocol :// hostname[:port] / path / [;parameters][?query]#fragment

parameter Explanation
protocol Specified protocol (e.g., http, https, etc.)
hostname

Domain Name System storage resources of the server (DNS) host name or IP address.

Before the host name may also be required to connect to the server that contains the user name and password

(Format: username: password @ hostname)

port Port number, the default is 80
path Path consists of zero or more "/" symbol string spaced, generally used to indicate a file or directory on the host address
parameters It is used to specify a particular parameter options
query

For a dynamic web page (e.g., using technology to produce CGI, ISAPI, PHP / JSP / ASP / ASP.NET pages, etc.) to pass parameters,

There may be a plurality of parameters, with the "&" symbol spaced, name and value of each parameter by "=" symbol spaced

fragment Anchor for specifying network resources clips 

 

  2, AT, URL 和 URN:

    ① URI of the (Uniform Resource identifier The): uniform resource identifier, which is an abstract resource identifier can be relative, it can be absolute

    ② the URL of (Uniform Resource LOCATION): Uniform Resource Locator, a specific URI of the , specify how to locate this resource must be absolute

    ③ URN (Uniform Resource name): Uniform Resource named resource identified by name

 

The HTTP request method:

  1, GET: request page information specified, and returns the entity body

  2, the POST: submit data processing request to the specified resource (e.g., file submission form or upload). Data contained in the request body.

                     POST requests may result in the modification of the establishment of new resources and / or existing resources

  . 3, the PUT: replace the contents of the designated document data transmission to the client from the server

  4, DELETE: requests the server to delete the specified page

  . 5, the HEAD: similar to the GET request, returns a response but not the specific content, for obtaining the header

  6、CONNECT:HTTP/1.1 协议中预留给能够将连接改为管道方式的代理服务器

  7、OPTIONS:允许客户端查看服务器的性能

  8、TRACE:回显服务器收到的请求,主要用于测试或诊断

  9、PATCH:是对 PUT 方法的补充,用来对已知资源进行局部更新

 

  POST 和 GET 的区别:

    1、大小不同:GET 方式的数据以明文的形式放在 URL 的首部中,大小会受到 URL 大小的限制,

                            而 POST 则把数据放到报文里,大小由报文大小来确定

    2、安全性不同:我们可以通过 URL 来查看 GET 的内容,而 POST 则不行,因此,敏感信息不应使用 GET 来传输

    3、使用目标不同:两者都用于获取资源,但 GET 仅仅是查询,POST 则常用于发送一定内容进行某些修改操作

 

HTTP 请求/响应步骤:

  1、客户端连接到 Web 服务器:建立一个 TCP 连接

  2、发送 HTTP 请求:通过 TCP,客户端向 Web 服务器发送一个文本的请求报文

  3、服务器接受请求并返回 HTTP 响应:Web 服务器解析请求,定位请求的资源

  4、释放 TCP 连接:

    ① 若 connection 模式为 close ==》服务器主动关闭 TCP 连接

    ② 若 connection 模式为 keepalive ==》连接保持一段时间,在该时间内可以继续接收请求

  5、客户端浏览器解析 HTML 内容:

    ① 客户端浏览器首先解析状态行,查看表明请求是否成功的状态代码

    ② 然后解析每一个响应头,响应头告知以下为若干字节的HTML文档和文档的字符集。

    ③ 客户端浏览器读取响应数据HTML,根据HTML的语法对其进行格式化,并在浏览器窗口中显示

注:一个请求报文由请求行、请求头部、空行和请求数据 4 部分组成

  一个响应报文由状态行、响应头部、空行和响应数据 4 部分组成

 

状态码:

  

状态码 含义
1** 服务器收到请求,需要请求者继续执行操作
2** 成功,操作成功地被接收并处理
3** 重新定向,需要进一步的操作以完成请求
4** 客户端错误,请求包含语法错误或无法完成请求
5** 服务器错误,服务器在处理请求的过程中发生了错误

  常见状态码:

    200:请求成功

    301:资源被永久转移到求它 URL

    404:请求资源不存在

    500:内部服务器错误

 

Guess you like

Origin www.cnblogs.com/lemonyam/p/11489501.html