Format of HTTP request mode and response protocol

Source: Internet
Author: User
Tags http request response code
requests and responses for HTTP Protocols
first, about the HTTP protocol

1.HTTP (Hypertext Transport Protocol), which is the Hypertext Transfer Protocol.

This protocol details the rules for communicating with each other between the browser and the World Wide Web server.

2. What is transmitted when the client communicates with the server is what we call a message.

3.HTTP is a communication rule that specifies the message format that the client sends to the server,

The message format that the server sends to the client is also specified. What we are actually learning is these two kinds of messages.

The client is sent to the server called the "request Message", the server is sent to the client called "Response message."

II. protocol format for requests
Figure 2

HTTP protocol format for requests

Request first line; Request
header information;
blank line;
request body;

Request divided into Get and Post two ways

<1>get Way

Figure 1:

<2>psot protocol

(2), the description of the common request header

get/hello/index.jsp Http/1.1:get request, the request server path is hello/index.jsp, the protocol is 1.1;
Host:localhost: The requested host name is localhost;
user-agent:mozilla/4.0 (compatible; MSIE 8.0 ... : Information related to the browser and the OS. Some sites will display the user's system version and browser version information, which is obtained by user-agent header information;
Accept: */*: Tell the server, the current client can receive the document type, */*, it means that anything can be received;
ACCEPT-LANGUAGE:ZH-CN: Languages supported by the current client, language-related information can be found in the browser's tools  option,
accept-encoding:gzip, deflate: supported compression formats. When data is passed on the network, the server compresses the data before sending it;
Connection:keep-alive: The client supports the link mode, maintains a period of time link, defaults to 3000ms;

(2), what are the Get and post requests

GET Request:

1), enter address in the browser address bar directly press ENTER  
2), click Hyperlink <a>  
3), GET request form submit  <form  mehtod= "Get" >
4), script Src= "", Introduction of external File  
5), img src= "path", introduction of picture
6), introduction of external CSS ...

POST request:

1) Only when the form is submitted method=post, the submission form is the POST request

II. protocol format for responses

Response header information for the first line response in a
blank line

Figure 3

(2) Common response codes

The response code is important to the browser, which tells the browser the result of the response;
200: The request succeeds, the browser will display the response body content (usually HTML) in the browser,
404: The requested resource is not found, indicating that the client failed to request a non-existent resource;
500: The request resource was found, but there was an error inside the server,
302: Redirect, when the response code is 302, indicating that the server requires the browser to resend a request, the server sends a response header location, which specifies the URL address of the new request;

Summarize:

In the format of the HTTP request is divided into three parts the first part: The second part of the request
line: The third part of the request header: The request

line is divided into three parts the
first part is  the way of the request the
second part is  requested resource path The 
third part is the  requested protocol and version number

-----------------------------------------------
in the POST request, The HTTP protocol has three parts
in the GET request, the HTTP protocol has two parts
-----------------------------------------------

the HTTP protocol format
of the response Divided into three parts the first part is the response   line The
second part is the  response header
empty line the
third part is the  response Body

response line is divided into three parts the
first part of the HTTP protocol and version number
Part Two response code   200 request successful
third part response description  OK OK  indicates request response succeeded 

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.