HTTP protocol early entry

Hyper Text Transfer Protocol is based on requests and responses stateless protocol

First, a browser requests content from the server

A HTTP request has four parts: the request line, the request header, request data and blank lines

1, the request line

Tag consists of three components: request method, URI requests and HTTP version, respectively, separated by spaces

For example: GET / index.html HTTP / 1.1

And wherein HTTP1.0 predetermined HTTP1.1, total of eight request method

  • GET, retrieve the URI indicated resource of a simple request
  • HEAD, GET method with, the server returns only the status line and the headers, requests the document does not return
  • POST, the server receives client input data is written in the stream request
  • Request PUT, server saves the data as specified request URI of new content
  • Request DELETE, the server deletes the named resource URI
  • OPTIONS, request method of requesting information about the server support
  • TRACE, web server HTTP request and its feedback request headers
  • CONNECT, a method has been documented but is not currently implemented, do reserve tunneling

In the web applications, usually only GET and POST requests

2, the request header

Inform the server about the client's identity and function, the key / value pairs, one pair per line, separated by:, typical request header are:

  • User-Agent, manufacturers and versions of the client
  • Accept, the client may identify the content type list
  • Content-Length, attached to the request data bytes

3, blank lines. After the last request header is a blank line, send carriage returns and retrograde notification server no longer has the following header

4, the requested data. Using the data transmitted POST

Second, the server responds

web server receives the request, parses the request. If the request is a static resource, then the requested resource is returned to the browser, if the request is dynamic server program, such as servlet, JSP, ASP, CGI, etc., then after running the server returns the result of running the program.

A response consists of four parts

1, the status line. Composed of three markers

  • HTTP version
  • Results three digit code indicating the request: response code
  • Response Description: code interpretation response

Such as: HTTP / .1 200 OK

Attachment: the HTTP response status codes (rpm):

1 **: receiving a request, continue processing
2 **: the operation is successfully received, analyzed, accepting
3 **: complete the request must be processed further
4 **: contains a syntax error or not complete a request
the server to execute: 5 ** a perfectly valid request failed

100-- customers must continue to make requests
101-- client asks the server to convert the HTTP protocol version upon request

200-- successful transaction
201-- prompted know the URL of the new file

202-- accept and process, but the process is not completed
203-- return uncertain or incomplete information
204-- receipt of the request, but returned information is null
205-- server completes the request, the user agent must reset the current file has been viewed
206-- server has completed GET request some users

300-- resource request can be obtained in many
301-- deletion request data
302-- address found in other requested data
303-- advise clients to access the URL or other access methods

304-- client has performed a GET, but the file unchanged
305-- requested resource from the server must be specified address
codes 306-- previous version of HTTP used in the current version is no longer used
307-- stated delete temporary resource request

400-- Bad Request, such as syntax errors
401-- request authorization failed
402-- retains effective response ChargeTo head
403-- request does not allow
404-- not find a file, query or URl
405-- in the Request-Line user-defined fields the method does not allow
406-- Accept transmitted from the user according to drag, the requested resource is inaccessible
407-- 401 Similarly, the user must first be authorized on the proxy server
408-- client request is not completed within a user specified time hungry
409-- the current state of the resource, the request can not be completed
no longer on the server resource and 410-- no further reference address
411-- Content-Length server rejected the user-defined attribute request
412-- one or more requests in the request header field of the current error
resource 413-- requested size is greater than the server allows
the resource server 414-- requested URL is longer than the length allowed
415-- requested resource does not support the requested item format
416-- request including a Range header field of the request, resource request in the current no value within the range indicated range, the request
does not comprise request If-range header field
417-- service Expect header field specifies the request does not satisfy expectations, if a proxy server may be the
primary server can not satisfy the request

500-- server generates an internal error
501-- server does not support the requested function

502-- server is temporarily unavailable, and sometimes in order to prevent system overload
503-- server overload or suspend service
504-- mark overload, the server uses another mark in response to a user or service, a long wait time setting
505-- server does not support the request or reject branched HTTP version specified in the header

6xx  Proxy Error
600  Unparseable Response Headers (Squid-specific)

Detailed explanation:

100   the Continue initial request has been accepted, the client should continue to send the remaining portion of the request. (HTTP 1.1 new)

101   Switching Protocols server converts the client request to comply with another protocol (HTTP 1.1 new)

200   the OK everything is normal, the response document for GET and POST requests followed.

201   the Created server has created the document, Location head gives its URL.

202   Accepted has accepted the request, but the process has not been completed.

203   Non-Authoritative Information Document has returned normally, but some of the response headers might be incorrect, since the document is a copy (HTTP 1.1 new).

204 No Content No new document, the browser should continue to display the original document. If you regularly refresh the page, and new user documentation can be determined Servlet enough, this status code is very useful.

205  Reset Content  没有新的内容,但浏览器应该重置它所显示的内容。用来强制浏览器清除表单输入内容(HTTP 1.1新)。

206  Partial Content  客户发送了一个带有Range头的GET请求,服务器完成了它(HTTP 1.1新)。

300  Multiple Choices  客户请求的文档可以在多个位置找到,这些位置已经在返回的文档内列出。如果服务器要提出优先选择,则应该在Location应答头指明。  

301  Moved Permanently  客户请求的文档在其他地方,新的URL在Location头中给出,浏览器应该自动地访问新的URL。

302  Found  类似于301,但新的URL应该被视为临时性的替代,而不是永久性的。注意,在HTTP1.0中对应的状态信息是“Moved Temporatily”。 出现该状态代码时,浏览器能够自动访问新的URL,因此它是一个很有用的状态代码。

注意这个状态代码有时候可以和301替换使用。例如,如果浏览器错误地请求http://host/~user(缺少了后面的斜杠),有的服务器返回301,有的则返回302。

严格地说,我们只能假定只有当原来的请求是GET时浏览器才会自动重定向。请参见307。 303 See Other 类似于301/302,不同之处在于,如果原来的请求是POST,Location头指定的重定向目标文档应该通过GET提取(HTTP 1.1新)。

304  Not Modified  客户端有缓冲的文档并发出了一个条件性的请求(一般是提供If-Modified-Since头表示客户只想比指定日期更新的文档)。服务器告诉客户,原来缓冲的文档还可以继续使用。

305  Use Proxy  客户请求的文档应该通过Location头所指明的代理服务器提取(HTTP 1.1新)。

307  Temporary Redirect  和302(Found)相同。许多浏览器会错误地响应302应答进行重定向,即使原来的请求是POST,即使它实际上只能在POST请求的应答是303时 才能重定向。由于这个原因,HTTP 1.1新增了307,以便更加清除地区分几个状态代码:当出现303应答时,浏览器可以跟随重定向的GET和POST请求;如果是307应答,则浏览器只 能跟随对GET请求的重定向。(HTTP 1.1新)

400  Bad Request  请求出现语法错误。

401  Unauthorized  客户试图未经授权访问受密码保护的页面。应答中会包含一个WWW-Authenticate头,浏览器据此显示用户名字/密码对话框,然后在填写合适的Authorization头后再次发出请求。

403  Forbidden  资源不可用。服务器理解客户的请求,但拒绝处理它。通常由于服务器上文件或目录的权限设置导致。

404  Not Found  无法找到指定位置的资源。这也是一个常用的应答。

405  Method Not Allowed  请求方法(GET、POST、HEAD、Delete、PUT、TRACE等)对指定的资源不适用。(HTTP 1.1新)

406  Not Acceptable  指定的资源已经找到,但它的MIME类型和客户在Accpet头中所指定的不兼容(HTTP 1.1新)。

407  Proxy Authentication Required  类似于401,表示客户必须先经过代理服务器的授权。(HTTP 1.1新)

408  Request Timeout  在服务器许可的等待时间内,客户一直没有发出任何请求。客户可以在以后重复同一请求。(HTTP 1.1新)

409 Conflict  通常和PUT请求有关。由于请求和资源的当前状态相冲突,因此请求不能成功。(HTTP 1.1新)

410  Gone  所请求的文档已经不再可用,而且服务器不知道应该重定向到哪一个地址。它和404的不同在于,返回407表示文档永久地离开了指定的位置,而404表示由于未知的原因文档不可用。(HTTP 1.1新)

411  Length Required  服务器不能处理请求,除非客户发送一个Content-Length头。(HTTP 1.1新)

412  Precondition Failed  请求头中指定的一些前提条件失败(HTTP 1.1新)。

413  Request Entity Too Large  目标文档的大小超过服务器当前愿意处理的大小。如果服务器认为自己能够稍后再处理该请求,则应该提供一个Retry-After头(HTTP 1.1新)。

414  Request URI Too Long  URI太长(HTTP 1.1新)。

416  Requested Range Not Satisfiable  服务器不能满足客户在请求中指定的Range头。(HTTP 1.1新)

500  Internal Server Error  服务器遇到了意料不到的情况,不能完成客户的请求。

501  Not Implemented  服务器不支持实现请求所需要的功能。例如,客户发出了一个服务器不支持的PUT请求。

502 Bad Gateway  服务器作为网关或者代理时,为了完成请求访问下一个服务器,但该服务器返回了非法的应答。

503 Service Unavailable  服务器由于维护或者负载过重未能应答。例如,Servlet可能在数据库连接池已满的情况下返回503。服务器返回503时可以提供一个Retry-After头。

504  Gateway Timeout  由作为代理或网关的服务器使用,表示不能及时地从远程服务器获得应答。(HTTP 1.1新)

505  HTTP Version Not Supported  服务器不支持请求中所指明的HTTP版本。(HTTP 1.1新)

6xx  Proxy Error
600  Unparseable Response Headers (Squid-specific)

2、响应头标。指出服务器的功能,标示出响应数据的细节。

3、空行。最后一个响应头标之后是一个空行,发送回车符和退行,通知服务器以下不再有头标

4、响应数据。HTML和图像等,也就是HTML本身。

三、服务器发完响应后关闭连接,浏览器解析响应内容。

  • 先解析状态行,查看请求是否成功的状态代码
  • 解析每一个响应头标,头标告知一下为若干字节的HTML
  • 读取响应数据HTML,根据HTML的语法和语义对其进行格式化后,在浏览器窗口中显示

示例:

四、POST和GET

GET:获得静态资源,将请求附加在URI后面作为参数传递,如获得动态资源,使用参数,如:http://www.domain.com?search=jead

POST:请求动态资源,将请求作为数据放在请求体中传送的。

转载于:https://www.cnblogs.com/JoannaQ/archive/2012/09/30/2709059.html

Guess you like

Origin blog.csdn.net/weixin_33998125/article/details/93058317