HTTP notes and Summaries (2) HTTP protocol (Request line) Request method and (response line) status code

Source: Internet
Author: User
Tags browser cache

The request method (Request line) includes:

Get,post,head,put,trace,delete,options

Note: Although these request methods are specified by the HTTP protocol, Web Server may not allow or support these methods.

HEAD and GET are basically the same, but do not return content, such as just to confirm that a content is still there, do not need to return the specific content. Demonstrate:

GET:

HEAD:

The head method returns only the header information for the response.

PUT, transfer content to a resource on the server:

The server does not necessarily support the methods specified by the HTTP protocol.

Trace, such as using a proxy for Internet access (for example, access to news.163.com), you can use TRACE to see if the agent has modified the HTTP request (163.com server will return the last received request):

Similarly not allowed, the other server does not allow the TRACE method to be used.

Options, returns the available request methods for the server:

OPTIONS are not allowed.

Test with your own local server:

Status code (response line) , state text

The status code is used to reflect the response of the server;

State text is used to describe the status code.

Status code Defined Description
1XX Information Receive a request, continue processing
2XX Success Operation successfully received, understood and accepted
3XX redirect Further measures must be taken in order to complete the request
4XX Client Error The syntax of the request is wrong, or is not fully satisfied
5XX Service-side Error The server was unable to complete an apparently valid request

Common Status Codes

OK: The server successfully returned to the webpage;

301/302: Permanent/temporary Jump , example:

301 Redirects:

Run redirect.php

<?php//301 Permanent REDIRECT Header (' location:http://www.baidu.com ', true, 301);

  

302 Redirects:

Run redirect.php

<?php//302 Temporary REDIRECT Header (' location:http://www.baidu.com ');

  

Note : When post data is sent to a.php,a.php (header ("location:b.php"), redirect to B.php (Print_r ($_post);), the result is that the data received by the b.php is Array ().

Cause: From form to a.php is a POST request, from a.php to b.php becomes a GET request (as can be seen from the F12 developer tools)

Solution:

If you want to keep the POST request, you can use 307 : Redirect to keep the original data . a.php:

<? Phpheader ("location:b.php"true307);

Can. At this point a.php to b.php is still a POST request.

304 not Modified: unmodified (browser cache), for example

When you visit a page for the first time:

When the page is refreshed several times:

The client (Chrome) tells the service that I have this picture and tells the server the number on the picture time (If-modified-since and If-none-match), asks the server if the picture is out of date, and if it expires, pass me the latest picture. The server tells the browser (ETag and last-modified) that the image has not been modified, so the browser takes the image out of the cache, reducing the pressure on the server.

Test with Telnet for caching, normal GET request Picture:

Returns the binary picture information;

Add the following information:

If-modified-since:sun, 13:46:57 gmtif-none-match: "1860000000012c5-9d39-506e076b8dbb5"

Return:

Failed status code:

404: The requested webpage does not exist;

503: The server is temporarily unavailable;

500: Server Internal Error

HTTP notes and Summaries (2) HTTP protocol (Request line) Request method and (response line) status code

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.