HTTP protocol Image Display

Source: Internet
Author: User
Tags response code domain server

About the HTTP protocol: we split into several modules saying:

HTTP protocol :

HTTP is an object-oriented protocol belonging to the application layer, which is suitable for distributed hypermedia information System because of its simple and fast way.

The main features of the HTTP protocol can be summarized as follows:

1. Support Client/server Mode.

2. Simple and fast: when a customer requests a service from the server, it simply transmits the request method and Path. The request method commonly has, POST. Each method specifies a different type of contact between the customer and the Server. Because the HTTP protocol is simple, the HTTP server's program size is small, so the communication speed is Fast.

3. Flexible: HTTP allows the transfer of any type of data object. The type being transmitted is marked by Content-type.

4. No connection: the meaning of no connection is to limit the processing of only one request per Connection. When the server finishes processing the Customer's request and receives the Customer's answer, the connection is Disconnected. In this way, the transmission time can be saved.

5. Stateless: The HTTP protocol is a stateless Protocol. Stateless means that the protocol has no memory capacity for transactional processing. A lack of state means that if the previous information is required for subsequent processing, it must be re-routed, which may cause the amount of data to be transferred per connection to Increase. On the other hand, it responds faster when the server does not need the previous Information.


no connection : When the server finishes processing the Customer's request and receives the Customer's response, the connection is Disconnected. The early reason for this is that the HTTP protocol is generated on the internet, so the server needs to deal with Web access for hundreds of thousands of and millions of clients around the world, but the exchange of data between each client (that is, the Browser) and the server is intermittent (that is, the transmission is abrupt, instantaneous), and the Association of Web browsing, Divergence results in a low correlation of data for two transfers, and the number of processes and handles required to be open on the server is unacceptable, as paranoid945 says, and most channels are actually idle and Resource-intensive. therefore, the designer of HTTP intends to use this feature to design the protocol as a request to build a connection, to complete the release of the connection, as soon as possible to release resources to serve other Clients.

Over time, HTML pages have become more complex, with many images embedded in them, and it is inefficient to create a TCP connection every time a picture is Accessed. therefore, Keep-alive is proposed to solve the problem of low efficiency.

In this way, the HTTP connection between the client and the server is maintained, not disconnected (except for the time specified by keep-alive, unexpected power outages, etc.), and when the client sends another request, the established connection is Used.

stateless : Refers to the server does not know what the client State. HTTP is a stateless protocol, which means that each request is independent and keep-alive failed to change the Result.

Over time, however, people find static HTML boring and tedious, adding dynamically generated content to make Web applications more Useful.

thus, The syntax of HTML is constantly expanding, the most important of which is to add the form (form);

The client also adds features such as scripting, Dom processing, and, for servers, a corresponding CGI (Common Gateway Interface) to handle dynamic requests including form Submissions.

After the advent of a Web application in which the client interacts dynamically with the server, the HTTP stateless feature seriously hinders the implementation of these interactive applications, after all, and the simple shopping cart program

Know what product the user has chosen Before. As a result, two techniques for keeping the HTTP state are created, one is a cookie and the other is a Session.

A cookie is a Client's storage space, maintained by a browser.

In particular, the cookie mechanism uses a scheme that maintains state on the client, while the session mechanism uses a scenario that maintains state on the server Side.

At the same time, we also see that because the Server-side hold-state scheme also needs to save an identity on the client side, the session mechanism may need to use the cookie mechanism to achieve the purpose of preserving the identity, but there are actually other options, such as rewriting the URL and hiding the form Field.

first, the HTTP protocol detailed URL Chapter

HTTP (hypertext transfer Protocol) is a request-and-response mode-based, stateless, application-level protocol, often based on TCP connection, HTTP1.1 version of a continuous connection mechanism, the vast majority of Web development, is built on the HTTP protocol on the Web Application.

The HTTP URL (url is a special type of URI that contains enough information to find a resource) in the following format:

http://host[":" port][abs_path]

HTTP means to locate network resources through the HTTP protocol, the host represents a legitimate Internet host domain name or IP address; port specifies a port number, and NULL uses the default port 80;abs_path to specify the URI of the requested resource;

Abs_path is not given in the url, so when it is requested as a uri, it must be given in the form of "/", which is usually done automatically by the working browser.

eg

second, the HTTP protocol detailed request chapter

The HTTP request consists of three parts: the request line, the message header, the request body

1, the request line begins with a method symbol, separated by a space, followed by the requested URI and version of the protocol,

The format is as Follows: Method Request-uri http-version CRLF

Where method means the request, Request-uri is a Uniform resource identifier, http-version represents the HTTP protocol version of the request, CRLF indicates carriage return and newline (except for the CRLF at the end, a separate CR or LF character is not allowed).

The request method, which is all capitalized, is interpreted as follows: get     request gets the resource identified by Request-uri post    in the resource identified by Request-uri append new data head    Request to obtain a response message for a resource identified by Request-uri the put     request server stores a resource and uses Request-uri as its identity delete  request server to delete the resource identified by the Request-uri trace   request the server to echo received request information, primarily for testing or diagnosing connect to reserve future use of the Options request query server performance, or query resource-related options and requirements

Application Examples:

Get method: When you access a Web page by entering a URL in the address bar of the browser, the browser uses the Get method to fetch resources to the server, and the eg:get/form.html http/1.1 (CRLF) Post method requires the requested server to accept the data appended to the request and is often used to submit the FORM. eg:post/reg.jsp Http/(CRLF) accept:image/gif,image/x-xbit,... (CRLF) ... HOST:www.guet.edu.cn (CRLF) content-length:22 (CRLF) connection:keep-alive (CRLF) cache-control:no-cache (CRLF) (CRLF)         //the CRLF indicates that the message header has ended, preceded by a message header user=jeffrey&pwd=1234  //this line is the data submitted below

The head method is almost the same as the get method, and for the response part of the head request, the information contained in the HTTP header is the same as the information obtained through the Get Request.

Using this method, you can obtain information about the resources identified by Request-uri without transmitting the entire resource Content. This method is commonly used to test the validity of hyperlinks, whether they can be accessed, and whether they have been updated recently.

2. After the request header is described

3. Request Body (slightly)

third, the HTTP protocol detailed response Chapter

After receiving and interpreting the request message, the server returns an HTTP response message.

The HTTP response is also made up of three parts: status line, message header, response body
1, the status line format is as Follows:
Http-version Status-code reason-phrase CRLF
Where http-version represents the version of the server HTTP protocol, Status-code represents the response status code sent back by the server, and Reason-phrase represents a textual description of the status Code.
The status code consists of three digits, the first number defines the category of the response, and there are five possible values:
1xx: Indication information--indicates that the request has been received and continues processing
2xx: Success-indicates that the request has been successfully received, understood, accepted
3xx: Redirect--further Action 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, status descriptions, descriptions:

$ OK//client Request succeeded
Bad request//client requests have syntax errors and cannot be understood by the server
401 Unauthorized//request unauthorized, This status code must be used with the Www-authenticate header field
403 Forbidden//server receives request, but refuses to provide service
404 Not Found//request resource not present, eg: wrong URL entered
Internal Server Error//server Unexpected errors
503 Server Unavailable//server is currently unable to process client requests and may return to normal after some time
eg:http/1.1 OK (CRLF)


2. The response header is described later

3, The response body is the contents of the resources returned by the server

Iv. HTTP protocol Details of the message header chapter

HTTP messages consist of Client-to-server requests and server-to-client Responses. Both the request message and the response message are from the start line (for the request message, the start line is the request line, for the response message, the start line is the status line), the message header (optional), the empty line (only the CRLF line), and the message body (optional) is Composed.

The HTTP message header includes the normal header, the request header, the response header, and the entity Header.
Each header field consists of a name + ":" + a space + value, and the name of the message header field is Case-insensitive.

1. Normal Header
In the normal header, a small number of header fields are used for all request and response messages, but not for the transferred entity, only for the transmitted Messages.
eg

The Cache-control is used to specify the cache instruction, the cache instruction is unidirectional (the cache instruction appearing in the response may not appear in the request), and is independent (the cache instruction of one message does not affect the caching mechanism of another message processing), and HTTP1.0 uses a similar header domain of PRAGMA.

Cache directives at Request Include: No-cache (used to indicate that the request or response message cannot be cached), no-store, max-age, max-stale, min-fresh, only-if-cached;
Cache directives for response include: public, private, no-cache, no-store, no-transform, must-revalidate, proxy-revalidate, max-age, s-maxage.

Eg: in order to instruct IE browser (client) not to cache the page, the Server-side JSP program can be written as Follows: Response.sehheader ("cache-control", "no-cache");
Response.setheader ("Pragma", "no-cache"), function equivalent to the above code, usually both//shared
This code will set the normal header field in the Sent response message: Cache-control:no-cache

Date Normal header field indicates the day and time the message was generated

The connection normal header field allows the option to send a specified connection. For example, specify that the connection is contiguous, or specify a "close" option to notify the server to close the connection after the response is complete

2. Request Header

The request header allows the client to pass additional information about the request to the server side, as well as the client itself.

Common Request Headers

Accept

The Accept Request header field is used to specify which types of information the client Accepts. eg:accept:image/gif, indicating that the client wants to accept a resource in GIF image format; accept:text/html, indicating that the client wants to accept HTML Text.

Accept-charset

The Accept-charset request header field is used to specify the character set accepted by the Client. eg:accept-charset:iso-8859-1,gb2312. If the field is not set in the request message, the default is to accept any character set.
Accept-encoding

The Accept-encoding request header field is similar to accept, but it is used to specify acceptable content Encoding. Eg:accept-encoding:gzip.deflate. If the domain server is not set in the request message, the client is assumed to be acceptable for various content encodings.

Accept-language

The Accept-language request header field is similar to accept, but it is used to specify a natural language. Eg:accept-language:zh-cn. If the header field is not set in the request message, the server assumes that the client is acceptable for each language.

Authorization

The authorization request header domain is primarily used to prove that a client has permission to view a resource. When a browser accesses a page, if a response code of 401 (unauthorized) is received from the server, a request containing the authorization request header domain can be sent, requiring the server to validate it.

Host (the Header field is required when the request is Sent)

The host request header domain is primarily used to specify the Internet host and port number of the requested resource, which is usually extracted from the HTTP url, eg:

We enter in the Browser: http://www.guet.edu.cn/index.html

In the request message sent by the browser, the host Request header field is included, as Follows:

Host:www.guet.edu.cn

The default port number 80 is used here, and if a port number is specified, it becomes: Host:www.guet.edu.cn: Specify port number

User-agent

When we go online to the forum, often see some welcome information, which lists the name and version of your operating system, the name and version of the browser you are using, which often makes a lot of people feel amazing, in fact, the server application is from user-agent this request header domain to obtain this Information. The User-agent request header domain allows the client to tell the server about its operating system, browser, and other Properties. however, This header field is not required, and if we write a browser ourselves without using the User-agent request Header domain, Then the server side will not be able to know our Information.
An example of a request Header:

get/form.html http/1.1 (CRLF) accept:image/gif,image/x-xbitmap,image/jpeg,application/x-shockwave-flash, application/vnd.ms-excel,application/vnd.ms-powerpoint,application/msword,*/* (CRLF) ACCEPT-LANGUAGE:ZH-CN (CRLF) Accept-encoding:gzip,deflate (CRLF) if-modified-since:wed,05 Jan 11:21:25 GMT (CRLF) if-none-match:w/" 80b1a4c018f3c41:8317 "(CRLF) user-agent:mozilla/4.0 (compatible; MSIE6.0; Windows NT 5.0) (CRLF) Host:www.guet.edu.cn (CRLF) connection:keep-alive (CRLF) (CRLF)
3. Response Header

The response header allows the server to pass additional response information that cannot be placed in the status line, as well as information about the server and the next access to the resources identified by Request-uri.

Common response Headers

The Locationlocation response header field is used to redirect the recipient to a new Location. Location response header fields are commonly used when changing domain Names. The Serverserver response header field contains the software information that the server uses to process the Request. Corresponds to the user-agent request header Field. The following is an example of the Server response header field: The Server:apache-coyote/1.1www-authenticatewww-authenticate response header field must be included in the 401 (unauthorized) response message, When the client receives a 401 response message and sends the authorization header domain to the request server to validate it, the Service-side response header contains the header Domain. Eg:www-authenticate:basic realm= "Basic Auth test!"  You can see that the server is using a Basic authentication mechanism for the requested Resource.
4. Entity Header
Both request and response messages can send an Entity. An entity consists of an Entity header field and an entity body, but it does not mean that the entity header fields and entity bodies are sent together, and only the entity header fields can be Sent. The entity header defines the meta-information about the entity body (eg: there is no entity body) and the resource identified by the Request.
Common entity Headers
The Content-encodingcontent-encoding Entity header field is used as a modifier for the media type, and its value indicates the encoding of additional content that has been applied to the entity body, thus obtaining the media type referenced in the Content-type header Field. The corresponding decoding mechanism must be used. Content-encoding This method of compressing the document, the Eg:content-encoding:gzipcontent-languagecontent-language Entity header field describes the natural language used by the Resource. The domain is not set and the entity content is considered to be available to all language Readers. The Eg:content-language:dacontent-lengthcontent-length Entity header field is used to indicate the length of the entity body, expressed as a decimal number stored in Bytes. The Content-typecontent-type Entity header field term indicates the media type that is sent to the Recipient's entity Body. eg:content-type:text/html;charset=iso-8859-1content-type:text/html;charset= The Gb2312last-modifiedlast-modified Entity header field is used to indicate the last modification date and time of the Resource.

Enlighten

HTTP protocol Image Display

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.