HTTP request and Response format

Source: Internet
Author: User
Tags response code

Original: http://www.cnblogs.com/z941030/p/4699779.html

The HTTP protocol specifies the request format issued by the browser and the response format issued by the Web server.

The request part consists of three parts:

    • RequsetLine: Request lines, on the first line
    • Request Headers: Requests message header, starting from the second line to the end of the first empty line
    • Request body: The body after the first empty line

The response section is also made up of three parts:

    • ResponseLine: Response lines, in the first row
    • Response Headers: Response message header, starting from the second line to the end of the first empty line
    • ResponseBody: Response body, which is the body after the first empty line

One, HTTP request

The exact format of the HTTP request is as follows:

Method Path-to-resource Http/version-number

User-agent type of browser

The MIME type accepted by the Accept browser

Accept language User-selected accepted language

Accept-charset user-Preferred coded character set

......

Blank Line

Option Request Body

① Request Line:

1.Method is the request mode, including options,, POST, PUT, DELETE, TRACE, commonly used are GET and POST

Get features: The default request method.
When the requested resource path is/sdustexam/login.jsp?username=admin&password=123456, the Get method places the requested data for the form behind the requested URI. Username=admin &password=123456, this exposes the data, and the request line length is limited.

Post features (often used): Use form forms in HTML. <form action= "login.jsp" method= "POST" > Request parameters appear in the body section, the length of the wood is limited, relatively safe.

2.path-to-resource: The URI of the requested resource. such as/sdustexam/login.jsp

3.http/version-number: The version of the protocol used by the client, with http/1.0 and http/1.1.

http/1.0: Feature: Each time the resource on the request server establishes a new connection, the connection is closed when the response is complete. is a stateless protocol.
http/1.1: Features: On the basis of a TCP/IP connection, multiple requests and multiple responses can be made. A few more requests and response headers than 1.

② Request message Header

Passing additional information to the server

Accept: Notifies the server that the browser can accept the MIME type. (The type of data that is distinguished by the file name extension in the file system.) MIME types are used to differentiate data types on the network. Tomcat\conf\web.xml)
MIME type name: Large type/small type such as text/html, TEXT/CSS, etc.
ACCEPT-CHARSET: Notification server, browser-supported character set, such as Gbk,utf-8
Accept-encoding: Notifies the server that the browser can decode the data compression method. For example: gzip
ACCEPT-LANGUAGE: Notification server, desired language
Host: Requested hosts and ports
Referer: is a URL address. The value is the address of the page before the current page. For anti-theft chain
Content-type: Notifies the server of the MIME type of the request body. Value: application/x-www-form-urlencoded default value, which corresponds to the enctype attribute of the form form
If-modified-since: Notifies the server of the last modified time of the cached file.
User-agent: Notification server, browser type.
Content-length: Indicates the length of the request message body
Connection: Indicates whether a persistent connection is required. If the server sees the value here as "keep-alive", or sees that the request is using an HTTP 1.1 (HTTP 1.1 defaults to persistent connection)
Cookie: This is one of the most important request header information (session-related)

Second, HTTP response

The exact format of the HTTP response is as follows:

Http/version-number Statuscode Message

Type information for server servers

MIME type information for the Content-type response

Content-length the number of characters that are included in the corresponding type

......

Blank Line

Option Response Body

① Response Line:

Http/version-number: Protocol version used by the server
Statuscode: Response code. Represents a representation of the results processed by the server, and commonly used response codes are:
200: Normal
302/307: redirect
304: The server's resources have not been modified
404: The requested resource does not exist
500: Server Error
Message: Description of the response code. For example, the description of 200 is OK

② Response message Header:

Location: Notifies the client, indicating where the new resource is located (combined with 302/307). Request redirection)
Server: Notifies the client, the type of the server
Content-encoding: Notifies the client of the compression encoding of the response body. It is commonly used in gzip.
Content-length: Notifies the client of the data size of the response body
Content-type: Notifies the client of the MIME type of the response body
Refresh: Let the browser be refreshed automatically. The value is an integer (the time interval of the refresh, in seconds)
Refresh:3
Refresh:3; Url= URI for other resources
Content-disposition: Notifies the client to open the resource in a downloaded manner.
Content-disposition:attachment;filename=1.jpg
SET-COOKIE:SS=Q0=5LB_NQ; Path=/search server-Side Cookies sent (session-related)
Expires:-1 The effective time of the webpage. Unit is milliseconds, 1 for notifying clients not to cache
Cache-control:no-cache (1.1) Notifies the client not to cache
Pragma:no-cache (1.0) Notifies the client not to cache

HTTP request and Response format

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.