Request for the HTTP protocol

Source: Internet
Author: User

I. Basic format of the request

The basic format of the request consists of the request line, the request header, and the request entity three parts. For example:
Get/img/bd_logo1.png http/1.1
Accept: */*
referer:http://www.baidu.com/
Accept-language:zh-cn
Accept-encoding:gzip, deflate
user-agent:mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;. NET CLR 2.0.50727)
Host:www.baidu.com
Connection:keep-alive
cookie:baiduid=b0df0bdad30649f69a8930d11bdb6de8:fg=1;

(Request entity, but this is a GET request so no request entity)


1. Request Line:

On the first line of the request, the Method field, the URL field, and the HTTP version of the segment are recorded. For example:
Get/img/bd_logo1.png http/1.1
Above, get is the request method,/img/bd_logo1.png is the request url,http/1.1 is the request protocol and version.

2. Request Header:

Content that precedes a separate empty line after the request line, for example:
Accept: */*
referer:http://www.baidu.com/
Accept-language:zh-cn
Accept-encoding:gzip, deflate
user-agent:mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;. NET CLR 2.0.50727)
Host:www.baidu.com
Connection:keep-alive
Cookie:a=1

request header Detail:
Accept: The MIME type accepted by the browser, */* represents all types.
Referer: Contains a URL from which the user accesses the currently requested page from the page represented by the URL.
Accept-language: The type of language the browser wishes to use when the server is able to provide more than one language version.
Accept-encoding: The way the browser can encode data, such as gzip. The servlet can return a GZIP-encoded HTML page to a browser that supports gzip. In many cases this can reduce download time by 5 to 10 times times.
Accept-charset: A character set that is acceptable to the browser.
User-agent: Browser type, which is useful if the content returned by the servlet is related to the browser type.
Host: Hosts and ports in the initial URL, not displayed if the port is the default 80.
Connection: Indicates whether a persistent connection is required. If the servlet sees the value here as "keep-alive", or sees the request using an HTTP 1.1 (HTTP 1.1 is persistent by default), it can take advantage of the persistent connection, when the page contains multiple elements (such as applets, pictures), Significantly reduce the time it takes to download. To do this, the servlet needs to send a content-length header in the answer, and the simplest implementation is to write the content to Bytearrayoutputstream first and then calculate its size before formally writing the content.
Cookie: This is one of the most important request header information, usually at the end, because there may be a lot of content.

These are the most common request headers, some of which are not seen here:
Authorization: Authorization information, which typically occurs in an answer to the Www-authenticate header sent to the server.
Content-length: Represents the length of the request message body.
From: The email address of the requesting sender, used by some special Web client, is not used by the browser.
If-modified-since: Returns a 304 "not Modified" answer only if the requested content has been modified after the specified date.
Pragma: Specifying a value of "no-cache" means that the server must return a refreshed document, even if it is a proxy server and has a local copy of the page.
UA-PIXELS,UA-COLOR,UA-OS,UA-CPU: A nonstandard request header sent by some versions of Internet Explorer to indicate screen size, color depth, operating system, and CPU type.

3. Requesting entity:

After the request header and the empty line are the request entity, only the request for the Post method is requested.

Request for the HTTP protocol

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.