HTTP header description

Source: Internet
Author: User
Tags set cookie

Brief description of HTTP Header

1. Http return status code

In HTTP, the status code returned by the server is defined as follows:

1xx: informational. For example, the server requires authentication.

2XX: success. For example, 200 indicates that the server is correctly processed and the correct page is returned.

3xx: Redirection, indicating page redirection to another page or website.

4xx: client error. For example, 403 indicates that access is forbidden, and 404 indicates that the webpage to be accessed does not exist.

5xx: server error, internal server error. Status Code when the server fails to respond to the request correctly. For example, the CGI program does not output a header, or the output header does not end normally.

2. HTTP header Parameters

The HTTP header can contain multiple control parameters. Each parameter occupies one row. There is no sequential requirement between parameters. The parameter is followed by a line break and an empty line is added, indicating that the header ends. Common Control Parameters include:

Content-Type: the type of the page content, for example, text/html.

Content-Length: the number of returned page bytes (excluding the header), such as 12456.

Set-COOKIE: Set cookie. The format is: Cookie name = cookie value, and control attributes such as domain name and lifetime.

Location: sets the Redirection URL.

Pragma: usually used to tell the client browser whether to cache pages.

Expires: The expiration time when the page is cached.

An example of the HTTP header is as follows:

Content-Type: text/html; charset = gb2312

Content-Length: 3124

Set-COOKIE: A = B;

Location:/index. jsp

Pragma: No-Cache

Expires: 0

The HTTP return status code is also in the header, but usually does not need to be set by the program, which is automatically completed by the Web server.

In CGI programs such as C and Perl, you can directly output the HTTP header in the sample format. Note: The last parameter must be followed by two line breaks. Take C as an example:

Printf ("Content-Type: text/html; charset = gb2312n"); // page content and character set used

Printf ("Content-Length: 3124n"); // in CGI programs, this parameter is usually not required. Here, it is only used as an example.

Printf ("Set-COOKIE: A = B; nn"); // sets the cookie and ends the header.

In JSP, you can directly set HTTP header control parameters through the response object. The call method is as follows:

Response. setheader (name, value );

For example, the following code should be called in JSP when the browser does not need to cache the current page:

Response. setheader ("Pragma", "No-Cache"); // force refresh the page

Response. setheader ("expires", "0 ");

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.