HTTP protocol---Common request fields and HTTP response status codes and response headers in HTTP requests

Source: Internet
Author: User

Common request header fields for HTTP requests
Accept: For high-speed servers, client-supported data types
Accept-charset: Used to tell the server that the encoding format used by the client
Accept-encoding: Used to tell the server that the data compression format supported by the client
Accept-language: Language environment for Client
Host: Client through this header high-speed server, want to access the hostname
If-modified-since: The client tells the server through this header that the cache time of the resource
Referer: The client through this header tells the server, it is from which resources to access the server (anti-theft chain)
User-agent: The client uses this header to tell the server that the client's software environment
Cookies: The client can bring data to the server through this header
Connection: Do you want to disconnect or remain connected after processing this request?
Date: Current time value


HTTP response
Status line: Used to describe the result of the server's processing of the request.

Status code: 100~199: Represents a successful receive request, requiring the client to continue submitting the next request to complete the process.
200~299: Indicates that the request was successfully received and the entire process has been completed. Common 200
300~399: To complete the request, the customer needs to further refine the request. For example: The requested resource has moved a new address, commonly used 302 (meaning you ask me, I let you find someone else), 307 and 304 (I don't give you this resource, take the cache yourself)
400~499: Client request error, common 404 (meaning that the resource you requested is not on the Web server) 403 (server denied access, insufficient permissions)
500~599: Server side error, commonly used 500
Multiple response headers: The response header is used to describe the basic information about the server, and the description of the data, which the server can use to inform the client how to handle the data that is being echoed in a moment.
Location: This head is used with 302 status codes to tell customers who to look for.
Server: This header tells the browser the type of server.
Content-encoding: The server tells the browser the compression format of the data through this header.
Content-length: The server tells the browser the length of the loopback data through this header
Content-type: The server tells the browser the type of loopback data through this header
Last-modified: Tells the browser the last cached time of the current resource
Refresh: Tell the browser how often to refresh
Content-disposition: Tell the browser to open the data in the following way
Transfer-encoding: Tells the browser the data transfer format
ETag: Cache-Related headers
········ Three header fields that prevent browser caching:
Expires: Tell the browser how long to cache the loopback resource-1 or 0 is not cached
Cache-control:no-cache
Pragma:no-cache
Server through the above two headers, that is, control browser do not cache data

Entity content: Data that represents the server's loopback to the client

L 200 (normal) indicates that everything is normal and returns the normal request result. L 302/307 (temporary redirection) indicates that the requested document has been temporarily moved elsewhere, and that the new URL for this document is given in the location response header. L 304 (unmodified) indicates that the client-cached version is up to date and the client should continue to use it. L 403 (Forbidden) The server understands the client request but refuses to process it. This is usually caused by permission settings for the file or directory on the server. L 404 (Not Found) the resource requested by the client is not present on the server. L 500 (internal server error) server-side CGI, ASP, JSP, and other programs have errors.

1. Please describe the difference between HTTP 1.1 and HTTP 1.0 as you understand it. 2. Describe the composition of HTTP request messages and HTTP response messages, and explain them in one instance. 3. The browser uses the Get and post methods to access the Web server, respectively. If the browser passes to the Web server with more than 1K of parameter content, you should send the request message that way. 4. Describe the meaning expressed by response status Codes 200, 302, 304, 404, and 500.

5. List the three header fields that prevent browser caching and write down the appropriate setting values.

Answer:

1.http1.0 for each connection to establish a connection at a time can only send a request and response, the request will be closed, HTTP1.0 no host field;
HTTP1.1 can transmit multiple requests and responses in the same connection, multiple requests can overlap and simultaneously, HTTP1.1 must have a host field.

2. Request message structure: A request line, a number of message headers, and the contents of the corpse, some of the message headers and entity content are optional, the message header and the entity content to be separated by a blank line.
Response message structure: A status line, a number of message headers, and the contents of the corpse, some of which are optional, separated by a blank line between the message header and the entity content.
The difference is that the request message has a request line, and the response message has a status line.
Get/mail/aa.html http/1.1
Accept:text/html, Application/xhtml+xml, */*
Accept-language:zh-cn
user-agent:mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; trident/5.0)
Accept-encoding:gzip, deflate
host:localhost:8080
if-modified-since:wed-Oct 09:35:13 GMT
if-none-match:w/"62-1350466513174"
Connection:keep-alive

http/1.1 304 Not Modified
server:apache-coyote/1.1
etag:w/"62-1350466513174"
date:wed-Oct 09:45:38 GMT

3. The amount of data is small, because the get-mode data limit of 1K, without protection of data use get way to access the Web server, large amount of data, and with the need to protect the data to access the Web server by post way.
If the browser transfer server has more than 1K of data, you should use post to access the server, because when the post method sends data to the server, it packages the transferred data to the Web server.

4. What is the meaning of the response State:
200: Indicates success, normal result;
302: Redirect, go to another site;
304: no modification;
404: no resources found;
500: Internal server error;

5.Expires: Tell the browser how long to cache the loopback resource-1 or 0 is not cached
Cache-control:no-cache
Pragma:no-cache

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.