"NET Pick" HTTP protocol

Source: Internet
Author: User

HTTP protocol Details (blog Park):
http://kb.cnblogs.com/page/130970/

What is the HTTP protocol
Protocol refers to the rules or rules that must be adhered to in communication between two computers in a computer communication network, Hypertext Transfer Protocol (HTTP) is a communication protocol that allows Hypertext Markup Language (HTML) documents to be delivered from a Web server to the client's browser.
We are currently using the http/1.1 version

Web server, browser, proxy server
When we enter the URL, the browser sends a Request,web server to the Web server to process the request, generate the corresponding response, then send it to the browser, and the browser parses the HTML in the response so that we can see the page.
It is possible that our request was passed through a proxy server and ended up with a Web server. A proxy server is a transit point for network information, and its functions are:
1. Increased access speed, most proxy servers have caching capabilities.
2. Break the limit, that's FQ.
3. Hide identities.

URL detailed
Format: schema://host[:p ort#]/path/.../[;url-params][?query-string][#anchor]
Schema: Specifies low-level, practical protocols, such as Http,https,ftp
IP address or domain name of the host:http server
The default port for the Port#:http server is 80, in which case the lower number can be omitted. If you use a different port, you must indicate
Path: access to Resource paths
Url-params,query-string: Data sent to HTTP server
Anchor: Anchor

the HTTP protocol is stateless
There is no correspondence between this request and the last request of the same client, and it is not known to the HTTP server that the two requests are from the same client. To solve this problem, the Web program introduces a cookie mechanism to maintain state.

structure of the HTTP message
Request message structure: Divided into three parts, the first part called the request line, the second part is called the HTTP header, the third part is the body. There is a blank line between the header and the body, and the structure diagram is as follows:

The method in the first line represents the request methods, such as "POST", "GET", Path-to-resource represents the requested resource, and Http/version-number represents the version number of the HTTP protocol. When the "GET" method is used, the body is empty.
Response message structure: Also divided into three parts, the first part slogan should be line, the second part is called the response header, the third part is the body. There is also a blank line between the header and the body. Structures such as:

The Http/version-number represents the version number of the HTTP protocol, status code is state codes, and message is status messages

The difference between the Get and post methods
The HTTP protocol defines a number of ways to interact with the server, the most basic of which are 4, get,post,put,delete, respectively. A URL address is used to describe a resource on the network, while HTTP Get,post,put,delete corresponds to this resource's search, change, increase, and delete 4 operations. The most common are get and post, which are typically used to get/query resource information, and half for updating resource information.
The difference between get and post:
1. Get submitted data is placed after the URL, to split the URL and transfer data, the parameters are connected to &. The Post method is to put the submitted data in the body of the HTTP packet.
2. The data size of the get commit is limited, and the data submitted by the Post method is not limited
3. The Get method needs to use Request.QueryString to get the value of the variable, while the Post method obtains the value of the variable by Request.Form.

Status Code
The status code is used to tell the HTTP client whether the HTTP server produced the expected response.
The 5 class status codes are defined in http/1.1 and the status codes consist of three-bit numbers, and the first number defines the category of the response:
1XX hint Message-Indicates that the request has been successfully received and continues processing
2XX Success-Indicates that the request has been successfully received, understood, accepted
3XX redirection-Further processing is required to complete the request
4XX Client Error-Request syntax error or request not implemented
5XX server-side error-the server failed to implement a legitimate request
Common Status Codes:
OK: The request is completed successfully and the requested resource is sent back to the client
302 Found: Redirect, the new URL will be returned in Loacation in response, and the browser will send a new request using the new URL
304 Not Modified: Indicates that the last document has been cached and can continue to use
Bad Request: The client requests a syntax error and cannot be understood by the server
403 Forbidden: The server receives the request but refuses to provide the service
404 Not Found: Request resource does not exist
Internal Server error: Unexpected errors occurred on the server
503 Server Unavailable: The server is currently unable to process client requests and may return to normal after some time

HTTP Request Header

Cache Header Field
If-modified-since
Role: The last modification time of the browser cache page is sent to the server, and the server compares this time with the last modification time of the actual file on the server. If the time is the same, then return 304, the client uses the local cache file directly. If the time is inconsistent, 200 and the new file contents are returned. After the client receives it, it discards the old files, caches the new files, and displays them in the browser.
If-none-match
Function: works with the etag and works by adding etag information to the HTTP reponse. When the user requests the resource again, the If-none-match information (the value of the ETag) is added to the HTTP request. If the server verifies that the etag of the resource has not changed (the resource is not updated), it returns a 304 status that tells the client to use the local cache file. Otherwise, the 200 state and the new resource and ETag are returned. Using such a mechanism will improve the performance of your website.
Pragma
Role: Prevent the page from being cached, in the http/1.1 version, it is identical to the Cache-control:no-cache function
Cache-control
Role: Used to develop a caching mechanism that response-request follows. Each instruction has the following meanings:
Cache-control:public-can be cached by any cache
Cache-control:private-content is cached only in the private cache
cache-control:no-cache– All content is not cached
Other
Client Header Domain
Accept
Role: The browser side can accept media types, such as text/html, which are HTML documents. */* on behalf of the browser can handle all types (general browser to the server is this)
Accept-encoding
Role: The browser declares itself to accept the encoding method, usually specifies the compression method, whether compression is supported, what compression method is supported (Gzip,deflate)
Accept-language
Role: The browser affirms the language it receives.
User-agent
Role: tells the HTTP server which client uses the name and version of the operating system and browser.
Accept-charset
Role: The browser affirms its own received character set
cookie/login Header Field
Cookies
Role: The most important header, the value of the cookie is sent to the HTTP server
Entity Header Field
Content-length
Effect: The length of data sent to the HTTP server
Content-type
Role: The type of data sent to the HTTP server
Miscellaneous Header Field
Referer:
Function: Provides the context information for the request and tells the server which link I took from.
Transport Header Field
Connection
such as Connection:keep-alive: When a Web page opens, the TCP connection between the client and the server for transmitting HTTP data is not closed, and if the client accesses the Web page on the server again, the established connection will continue to be used.
such as Connection:close: After a request is completed, the TCP connection between the client and the server for transmitting HTTP data is turned off and the TCP connection needs to be re-established when the client sends the request again.
Host
Role: Used primarily to specify the Internet host and port number of the requested resource, usually extracted from the HTTP URL. This header field is required when a request is sent.

HTTP Response Header

Cache Header Field
Date
Effect: The exact time and date when the message was generated.
Expires
Role: The browser will use the local cache for the specified expiration period
Vary
cookie/login header field (not included)
P3p
Role: Used to set cookies across domains, which resolves the issue of cross-domain access to cookies for IFRAME
Set-cookie
Role: A very important header, used to send cookies to the client browser, each write cookie generates a Set-cookie.
Entity Header Field
ETag
Function: Used in conjunction with If-none-match
Last-modified
Role: Used to indicate the last modification date and time of a resource
Content-type
Role: The Web server tells the browser the type and character set of the object it responds to
Content-length
Function: Indicates the length of the entity body, expressed as a decimal number stored in bytes. In the process of data downlink, content-length the way to pre-cache all the data in the server, and then all the data peremptorily to the client.
Content-encoding
Role: The Web server indicates what compression method (Gzip,deflate) It uses to compress the objects in the response.
Content-language
Role: The Web server tells the browser to respond to the language of the object
Miscellaneous Header Field
Server
Function: Indicates the software information of the HTTP server
X-aspnet-version
Role: If the Web site is developed using ASP, this header is used to represent the version of ASP.
X-powered-by
Function: Indicates what technology the website uses to develop
Transport Header Field
Connection
Slightly
Location header Field
Locaion
Function: Used to redirect a new location, including a new URL address

"NET Pick" HTTP protocol

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.