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

Source: Internet
Author: User

Basic HTTP protocol

Open the browser, enter the server IP, such as http://192.168.0.3, if the port number is not A few, such as 8000, Then enter http://192.168.0.3:8000 . the HTTP protocol header that the browser sends to the server is as follows:

get/http/1.1

host:192.168.0.3:8000

user-agent:mozilla/5.0 (X11; U Linux i686; En-us; rv:1.8.1.6) gecko/20061201

firefox/2.0.0.6 (Ubuntu-feisty)

Accept:

text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/

png,*/*;q=0.5

accept-language:en-us,en;q=0.5

Accept-encoding:gzip,deflate

accept-charset:iso-8859-1,utf-8;q=0.7,*;q=0.7

keep-alive:300

Connection:keep-alive

Common request header fields for HTTP requests

Accept: For high-speed servers, the type of data supported by the client
Accept-charset: Used to tell the server the encoding format used by the client
Accept-encoding: Used to tell the server that the client supports the data compression format
Accept-language: The language environment of the 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 tells the server through this header which resource to access the server (anti-theft chain)
User-agent: The client tells the server through this header that the client's software environment
Cookies: This header allows the client to bring data to the server
Connection: Whether 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 processing the request.

Status code: 100~199: Indicates a successful receive request that requires the client to continue submitting the next request in order to complete the process.
200~299: Indicates that the request was received successfully and the entire process has been completed. Common 200
300~399: To complete the request, the customer needs to refine the request further. For example: The requested resource has moved a new address, common 302 (meaning you ask me, I ask you to find someone else), 307 and 304 (I do not give you this resource, take the cache yourself)
400~499: Client request has error, common 404 (means that the resource you requested is not in the Web server) 403 (server denied access, insufficient permissions)
500~599: Server side error, common 500
Multiple response headers: The response header is used to describe the basic information of the server, as well as the description of the data, the server through the description of the data, you can tell the client how to deal with the data it sends back in a moment.
Location: This header is used with the 302 status code to tell the customer 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 via this header
Content-type: The server tells the browser the type of the loopback data via this header
Last-modified: Tells the browser the last cache time of the current resource
Refresh: Tell the browser how often it refreshes
Content-disposition: Tell the browser to open the data in the download mode
Transfer-encoding: Tells the browser the data transfer format
ETag: Cache-Related headers
········ Three header fields that prohibit browser caching:
Expires: Tells 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 the browser do not cache data

Entity content: Data that is echoed back to the client on behalf of the server

L200 (normal) indicates that everything is normal and returns the normal request result. l302/307 (temporary redirection) indicates that the requested document has been temporarily moved elsewhere, and the new URL for this document is given in the location response header. l304 (unmodified) indicates that the client cache version is up-to-date and the client should continue to use it. The l403 (Forbidden) server understands the client request but refuses to process it. This is usually due to the permissions set on the file or directory on the server. l404 (not found) the resource requested by the client does not exist on the server. L500 (internal server error) a server-side CGI, ASP, JSP, and other programs have an error.

1. Please describe the difference between HTTP 1.1 and HTTP 1.0 as you understand it. 2. Describe the composition of the HTTP request message and the HTTP response message, and each example is described. 3. In what situations does the browser use Get and post to access the Web server separately? If the browser passes the parameter content of the Web server to more than 1K, should the request message be sent in that way? 4. Please describe the meaning of response status codes 200, 302, 304, 404, and 500.

5. Please list three types of header fields that prohibit browser caching and write out the corresponding settings.

Answer:

1.http1.0 only one request and response can be sent once for each connection, the request is closed, and the HTTP1.0 does not have a host field;
While HTTP1.1 can transmit multiple requests and responses in the same connection, multiple requests can overlap and simultaneously, and 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 header and entity content are optional, between 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 the message header and entity content are optional, the message header and the entity content to be separated by a blank line.
The difference between the two: 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 not large, because the Get mode data volume limit 1K, without protection data with the use of Get access to the Web server, data volume, and with the need to protect the data with the use of post to access the Web server.
If the data volume of the browser delivery server is more than 1K, the server should be accessed by post, because the transmitted data is packaged to the Web server when the post is sent to the server.

4. What is the meaning of the response status:
200: Expression of success, normal result;
302: Redirect, go to another site;
304: not modified;
404: Indicates that the resource cannot be found;
500: Indicates an 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

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

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.