Http request and response, Http Request Response

Source: Internet
Author: User

Http request and response, Http Request Response
 

The Http Protocol specifies the Request format sent by the browser and the Response format sent by the Web server.

 

The request consists of three parts:

  •  Requset line: Request line, located in the first line
  •  Request headers: Request Message Header, starting from the second line to the end of the first blank line
  •  Request body: Request body, which is followed by the first blank line

The response is composed of three parts:

  •  Response line: Response line, located in the first line
  •  Response headers: Response Message Header, starting from the second line to the end of the first blank line
  •  Response body: Response body, which is followed by the first blank line

 

1. Http request

 

The specific Http request format is as follows:

Method Path-to-resource Http/Version-number

User-agent Browser type

MIME Type accepted by the Accept Browser

Accept language

Accept-charset user preferred encoding Character Set

......

Empty row

Option Request Body

 

① Request line:

1. The Method is the request Method, including OPTIONS, GET, HEAD, POST, PUT, DELETE, and TRACE. commonly used methods include GET and POST.

GET features: the default request method.
When the requested resource path is/SdustExam/Login. jsp? When username = admin & password = 123456, The GET method places the data requested by the form following the request URI ,? Username = admin & password = 123456, which exposes data and the length of the request line is limited.

POST features (frequently used): use form forms in HTML. <Form action = "Login. jsp" method = "post"> the request parameter appears in the body section. The length of the request is limited by wood and is relatively safe.

 

2. Path-to-resource: The URI of the requested resource. For example,/SdustExam/Login. jsp

 

3. Http/Version-number: The Protocol Version used by the client, including HTTP/1.0 and HTTP/1.1.

HTTP/1.0: feature: each time a resource on the server is requested, a new connection is required, and the connection is closed after the response is complete. Is a stateless protocol.
HTTP/1.1: features: based on a single TCP/IP connection, you can send multiple requests and receive multiple responses. There are more request and response headers than 1.0.

 

② Request Message Header

Transmit additional information to the server

Accept: indicates the MIME type that the browser can Accept. (In the file system, the file extension is used to differentiate data types. MIME types are used to differentiate data types on the network. Tomcat \ conf \ web. xml)
MIME Type name: Large/small types such as text/html and text/css
Accept-Charset: indicates the Notification Server. The character sets supported by the browser, such as gbk and UTF-8.
Accept-Encoding: indicates the data compression method that can be decoded by the browser on the notification server. For example, gzip
Accept-language: indicates the language of the Notification Server.
Host: Requested Host and Port
Referer: a URL. The value is the address of the page before the current page. Anti-leech
Content-Type: MIME Type of the Request body on the notification server. Value: default value of application/x-www-form-urlencoded, which corresponds to the enctype attribute of form.
If-Modified-Since: indicates the last modification time of the cached file on the notification server.
User-Agent: Notification Server, browser type.
Content-Length: the Length of the Request Message Body.
Connection: Indicates whether a persistent Connection is required. If the server sees the value "Keep-Alive" or the request uses HTTP 1.1 (HTTP 1.1 performs a persistent connection by default)
Cookie: This is one of the most important request header information (Session-related)

 

Ii. http response

 

The specific http Response format is as follows:

Http/Version-number Statuscode message

Server type information

MIME type information of the Content-type response

Content-length contains the number of characters in the corresponding type

......

Empty row

Option Response Body

 

① Response line:

Http/Version-number: Protocol Version used by the server
Statuscode: response code. A representation of the server processing result. Common Response codes include:
200: normal
302/307: Redirection
304: the server's resources have not been modified
404: the requested resource does not exist.
500: Server Error
Message: response code description. For example, the description of 200 is OK.

 

② Response Message Header:

Location: notifies the client of the Location of the new resource (combined with 302/307. Request redirection)
Server: Notification client, Server type
Content-Encoding: indicates the compression Encoding method of the response body to the client. Gzip is commonly used.
Content-Length: size of the response body of the notification Client
Content-Type: MIME Type of the response body of the notification Client
Refresh: Refresh the browser automatically. The value is an integer (the interval of refreshing, in seconds)
Refresh: 3
Refresh: 3; URL = URI of other resources
Content-Disposition: notifies the client to open the resource as a download.
Content-Disposition: attachment?filename=1.jpg
Set-Cookie: SS = Q0 = 5Lb_nQ; path =/Cookie sent by the search server (Session-related)
Expires:-1 webpage validity period. The Unit is milliseconds.-1 indicates that the client is not cached.
Cache-Control: no-cache (1.1) notifies the client not to Cache
Pragma: no-cache (1.0) notifies the client not to cache

Related Article

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.