HTTP protocol Overview

Source: Internet
Author: User

Features of HTTP 1.1
Multiple HTTP requests and responses can be delivered on a single TCP connection
Multiple request and response processes can overlap
Added more request headers and response headers

HTTP request message
Structure of the request message:
A request line, a number of message headers, and the entity content, where some of the message headers and entity contents are optional, separated by a blank line between the message header and the entity content.
Example:
get/books/java.html http/1.1//Request Line
Accept: */*//Multiple message headers
Accept-language:en-us
Connection:keep-alive
Host:localhost
Referer:http://localhost/links.asp
user-agent:mozilla/4.0
Accept-encoding:gzip, deflate
A blank line


HTTP Response message
Structure of the response message:
A status line, a number of message headers, and the entity content, where some of the message headers and entity contents are optional, separated by a blank line between the message header and the entity content

Example:
http/1.1 OK//status line
server:microsoft-iis/5.0//Multiple message headers
Date:thu, Jul 05:46:53 GMT
content-length:2291
Content-type:text/html
Cache-control:private
A blank line
<HTML>//entity content
<BODY>
....


The entity content of the response message is the content of the Web page file, which is what you see in the browser using the view source file.
A request message that uses a GET method cannot contain entity content, and only the content of the entity can be contained in a request message that uses post, put, and delete methods.
For HTTP 1.1来, if the HTTP message includes the entity content, and the chunked transfer encoding is not used, the message header part must contain the field of the content length, otherwise the client and the service program will not know when the entity content ends.
In the HTTP protocol, you can also use a simple request message and a response message, none of which have a message header section. A simple request message can only be used in get mode, and the HTTP version number is not specified in the request line. For a simple request message, the server returns a simple response message, and only the entity content is returned in a simple response message.

HTTP message Header
With the message header, you can implement conditional requests and responses between the HTTP client and the server, which is equivalent to some password instructions between the server and the browser. Each message header contains a header field name, followed by a colon, a space, a value, a carriage return, and a newline character. Example: accept-language:en-us. The message header field names are case-insensitive, but are used to capitalize the first letter of each word. Each line of the message header in the entire message header can be sorted in any order.
The message header can be divided into general information header, request header, response header, entity class four.
Many request header fields allow clients to specify multiple acceptable options in the Value section, with multiple items separated by commas. Example: Accept-encoding:gzip, compress some header fields can appear multiple times, for example, a response message can contain more than one "Warning" header field.

Request line and status line
Request Line
Format: Request way resource Path HTTP version number <CRLF>
Example: get/test.html http/1.1
Request method: POST, HEAD, OPTIONS, DELETE, TRACE, PUT
Status line
Format: HTTP version number status code reason description <CRLF>
Example: http/1.1 OK

Passing parameters using GET and post
You can attach some parameters after the URL address
Example: http://www.it315.org/servlet/ParamsServlet?param1=abc&param2=xyz
Get mode
Example: Get/servlet/paramsservlet?param1=abc&param2=xyz http/1.1
Features: The amount of data transmitted is limited, the general limit is less than 1KB.
Post mode
Example:
Post/servlet/paramsservlet http/1.1
Host:
content-type:application/x-www-form-urlencoded
Content-length:28

Param1=abc&param2=xyz
Features: The amount of data transferred is much larger than the amount of data sent in the Get mode.


Response Status Code
The response status code is used to represent the different processing results and status of the server to the request, which is a three-bit decimal number. Response status codes can be categorized into 5 categories, using the highest bits of 1 to 5来, as follows:
(1) 100~199
Indicates a successful receive request that requires the client to continue submitting the next request in order to complete the process.
(2) 200~299
Indicates that the request was received successfully and that the entire process has been completed.
(3) 300~399
To complete the request, the customer needs to refine the request further. For example, the requested resource has moved a new address.
(4) 400~499
The client request has an error.
(5) 500~599
There was an error on the server side.

Response status code--typical case
200 (normal)
Indicates that everything is OK and returns the normal request result.
206 (partial content)
The client sends a GET request with a range header (which requires the server to return only a portion of the document), and the server completes the request as requested.
302/307 (Temporary redirect)
Indicates that the requested document has been temporarily moved elsewhere, and the new URL for this document is given in the location response header.
304 (not modified)
Indicates that the client cache version is up-to-date and the client should continue to use it.
401 (Unauthorized)
Indicates that the client is accessing a password-protected page with a www-authenticate response header prompting the client to re-issue a request message with a authorization header.
404 (Not Found)
The resource requested by the client does not exist on the server.
500 (internal server error)
Server-side CGI, ASP, JSP and other programs have errors.

General Information Header
The Common Information header field can be used both for request messages and for response messages, including some common message header fields that have no relation to the entity content being transferred.
Cache-control:no-cache
Connection:close/keep-alive
Date:tue, Jul 18:23:51 GMT
Pragma:no-cache
Trailer:date
Transfer-encoding:chunked
upgrade:http/2.0, shttp/1.3
via:http/1.1 Proxy1, http/1.1 Proxy2
Warning:any text

The

Request Header
Request header field is used by the client to pass additional information to the server in the request message, mainly including information such as the type of data that the client can accept, the compression method, the language, and the URL address of the Web page to which the requested hyperlink belongs.
accept:text/html,image/*
Accept-charset:iso-8859-1,unicode-1-1
accept-encoding:gzip,compress
ACCEPT-LANGUAGE:EN-GB,ZH-CN
Authorization:basic enh4ojeymzq1ng==
expect:100-continue
From: [email  Protected]
host:www.it315.org:80
If-match: "Xyzzy", "r2d2xxxx"
If-modified-since:tue, Jul 18:23:51 G MT
If-none-match: "Xyzzy", "r2d2xxxx"
If-range:tue, Jul 18:23:51 GMT
if-unmodified-since:tue, 20 Jul XX 18:23:51 GMT
max-forwards:1
proxy-authorization:basic enh4ojeymzq1ng==
range:bytes=100-599
Range: bytes=100-
range:bytes=-100
referer:http://www.it315.org/index.jsp
te:trailers,deflate
User-Agent: mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)

Response header
The Response header field is used by the server to pass additional information to the client in the response message, including information such as the name of the service program, the authentication method required by the requested resource, and the new address to which the requested resource has been moved.
Accept-range:bytes
age:315315315
Etag:b38b9-17dd-367c5dcd
location:http://www.it315.org/index.jsp
Proxy-authenticate:basic realm= "it315"
Retry-after:tue, Jul 18:23:51 GMT
server:microsoft-iis/5.0
Vary:accept-language
Www-authenticate:basic realm= "it315"

Solid Head
Entity headers are used as meta-information for entity content, describing the attributes of entity content, including entity information type, length, compression method, last modification time, data expiration, and so on.
Allow:get,post
Content-encoding:gzip
Content-language:zh-cn
Content-length:80
Content-location:http://www.it315.org/java_cn.html
content-md5:abcdabcdabcdabcdabcdab==
Content-range:bytes 2543-4532/7898
content-type:text/html; charset=gb2312
Expires:tue, Jul 18:23:51 GMT (*)
Last-modified:tue, Jul 18:23:51 GMT

Expansion Head
In the HTTP message, you can also use some header fields that are not defined in the HTTP 1.1 formal specification, which are collectively referred to as custom HTTP headers or extension headers, which are often treated as a solid header.
Today's popular browsers actually support several commonly used extension header fields such as cookies, Set-cookie, refresh, and content-disposition.
Refresh Header Field
Refresh:1
refresh:1;url=http://www.it315.org
Content-disposition header Field
Content-type:application/octet-stream
Content-disposition:attachment; Filename=aaa.zip

HTTP protocol Overview

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.