In-depth understanding of the HTTP protocol (ii)--a detailed agreement

Source: Internet
Author: User
Tags date time stamp http request requires response code rfc
comparison of 1.http/1.0 and http/1.1

RFC 1945 defines the http/1.0 version, and RFC 2616 defines the http/1.1 version. 1.1 Establishing connection aspects

http/1.0 each request requires a new TCP connection and the connection cannot be reused. http/1.1 a new request can be sent on top of the last TCP connection that was requested, and the connection can be reused. The advantage is to reduce the overhead of repeating the TCP three handshake and increase the efficiency.

Note: In the same TCP connection, the new request needs to wait until the last request receives a response before it can be sent. 1.2 Host Domain

HTTP1.1 has a host domain in the request message header, and HTTP1.0 does not have this domain.

Eg:get/pub/www/theproject.html http/1.1
Host:www.w3.org

It may be HTTP1.0 that when a TCP connection is established, an IP address is specified, and there is only one host on the IP address. 1.3 Date Time stamp

(Receive direction)

Whether it is HTTP1.0 or HTTP1.1, must be able to parse the following three kinds of Date/time Stamp:sun, 1994 08:49:37 GMT; RFC 822, updated by RFC 1123
Sunday, 06-nov-94 08:49:37 GMT; RFC 850, obsoleted by RFC 1036
Sun Nov 6 08:49:37 1994; ANSI C ' s asctime () format

(Send direction)

HTTP1.0 requires that a third asctime format Date/time stamp not be generated;

HTTP1.1 requires only the generation of Date/time stamp in RFC 1123 (first) format. 1.4 Status Response code

The use of State Response Code (CONTINUE) status code allows the client to test the server with the request header before sending the request message body, to see if the server wants to receive the request body. Decide if you want to send the request body again.

The client contains expect:100-continue in the request header

After the server sees it, the client continues to send the request body if the Continue status code is returned. This is HTTP1.1.

In addition, 101, 203, 205 and other sexual status response code 1.5 requests are added in the http/1.1.

HTTP1.1 adds options, PUT, DELETE, TRACE, connect these request methods.

Method = "OPTIONS"; Section 9.2

| "GET"; Section 9.3

| "HEAD"; Section 9.4

| "POST"; Section 9.5

| "PUT"; Section 9.6

| "DELETE"; Section 9.7

| "TRACE"; Section 9.8

| "CONNECT"; Section 9.9

| Extension-method

Extension-method = Token

2.HTTP Request Message 2.1 Request Message Format

The request message format is as follows:

Request Line

General Information Header | Request Header | solid head

CRLF (carriage return and line break)

Entity content

where "request Line" is: Request line = method [space] request URI [space] version number [Return to line]

Request Line instance:

Eg1:get/index.html http/1.1

EG2:

POST http://192.168.2.217:8080/index.jsp http/1.1

HTTP Request Message instance: Get/hello.htm http/1.1
Accept: */*
Accept-language:zh-cn
Accept-encoding:gzip, deflate
if-modified-since:wed, Oct 02:15:55 GMT
if-none-match:w/"158-1192587355000"
user-agent:mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
host:192.168.2.162:8080
Connection:keep-alive 2.2 Request Method

The HTTP request methods include the following:

Q GET

Q POST

Q HEAD

Q PUT

Q DELETE

Q OPTIONS

Q TRACE

Q CONNECT

3.HTTP Response Message 3.1 Response message Format

The format of the HTTP response message is as follows:

Status line

General Information Header | Response Head | SOLID head

CRLF

Entity content

Where: status line = version number [space] status code [space] reason [carriage return line]

Examples of status lines:

eg1:http/1.0 OK

eg2:http/1.1 Bad Request

An HTTP response message instance is as follows: http/1.1 OK
etag:w/"158-1192590101000"
last-modified:wed, Oct 03:01:41 GMT
Content-type:text/html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.