Differences between HTTP protocol and get and post

Source: Internet
Author: User
Tags response code rfc

Picked from Wu Qin: http://www.cnblogs.com/skynet/archive/2010/05/18/1738301.html

1. Http Overview

To help you remember or understand the HTTP protocol, first let's look at the HTTP protocol.Hypertext Transfer Protocol

(HTTP

,Hypertext Transfer Protocol

) Is the Internet

The most widely used network protocol.

. All WWW

All documents must comply with this standard. The initial purpose of HTTP design is to provide a way to publish and receive html

PAGE method.

The development of HTTP is the World Wide Web Consortium

Internet Engineering Task Force

) Cooperation results, (they) finally released a series of RFC

The most famous one is RFC 2616.

. RFC 2616

Defines a widely used version of HTTP 1.1 in the HTTP protocol.

1.1 interaction between HTTP client and server

HTTP is the standard for client and server requests and responses (TCP

).The client is an end user.

,The server is a website

. By using a Web browser, web crawler, or other tools, the client initiates a specified port (default port

Is
80. (We call this client) Call the user proxy
Agent ). The response server stores (some) resources, such as HTML files and images. (We call this) The response server is the origin server
Server ). There may be multiple middle layers between the user proxy and the source server, such as the proxy, gateway, or tunnel ). Although the TCP/IP

Protocol is the most popular application on the Internet. Http does not stipulate that it must be used and (based on) the layer it supports. In fact, HTTP can be implemented on any other Internet protocol or on another network. HTTP only assumes that (provided by its lower-layer protocol) reliable transmission, any protocol that can provide such assurance can be used by it.

Connect
Generally, an HTTP client initiates a request to establish a TCP connection to the specified port on the server (port 80 by default. The HTTP server listens to the requests sent from the client on that port. I
Once a request is received, the server (to the client) sends back a status line, such as "HTTP/1.1 200
OK ", and (response) messages. The message body may be the requested file, error message, or other information.

The reason why HTTP uses TCP instead of UDP is that a webpage must transmit a lot of data, while TCP

The protocol provides transmission control, organizes data in order, and corrects errors. Requests over HTTP or HTTPSResource Identifier

(Uniform resource identifiers, or, more accurate, Uri) to identify.

The structure and interaction process between the client and the server can be shown in the following two figures:

Figure 1. Web client-server structure (the hypertext link of the Web server jumps to another server through a link on the website)

 

Figure 2 interaction between the Web client and the server

 

1.2. HTTP message

Two types of messages are used for client-to-server interaction:Request)

AndResponse)

.

The HTTP request format is:

Figure 3. http request format

 

The HTTP Response format is:

Figure 4. Http response format

 

From the above we can see that the HTTP request and Response Message Header both contain a variable number of fields, with a blank line (Blank line

) Convert allHeader field

(Header) andMessage Body

(Body) separated.A header field consists of a field name and a colon, a space, and a field value. The field name is case insensitive.

.

Packet headers can be divided into three types: requests, responses, and descriptions. Some headers (such as date) can be used for both requests and responses. The message header describing the subject can appear in the POST request and all response packets. Shows the HTTP header field:

Figure 5. HTTP header field

 

1.3. HTTP Request Method

HTTP/1.1 defines eight methods (sometimes called "actions") to indicateRequest-Uri

Different operations on the specified resource:

  • Options

    Returns the HTTP Request Method supported by the server for a specific resource. You can also use the '*' request sent to the Web server to test the server's functionality.

  • Head

    Request the server for the same response as the GET request, but the response body will not be returned. This method can obtain metadata contained in the Response Message Header without transmitting the entire response content.

  • Get

    Send a request to a specific resource. Note: The get method should not be used in operations that produce "Side effects", for example, in the Web Application

    . One of the reasons is that get may be attacked by web crawlers.

    .

  • Post

    Submits data to a specified resource for processing (for example, submitting a form or uploading a file ). Data is contained in the request body. POST requests may result in creation of new resources and/or modification of existing resources.

  • Put

    Upload the latest content to the specified resource location.

  • Delete

    Request server DeletionRequest-Uri

    Resource.

  • Trace

    The request received by the echo server is mainly used for testing or diagnosis.

  • Connect

    The HTTP/1.1 protocol is reserved for proxy servers that can change connections to pipelines.

The method name is case sensitive. When the resource for a request does not support the corresponding request method, the server should return status code 405 (method not allowed ); when the server does not recognize or support the corresponding request method, status code 501 (not implemented) should be returned ).

The HTTP server should at least implement the get and head methods. Other methods are optional. In addition to the preceding methods, the specific HTTP server can also extend the custom methods.

 

1.4 HTTP response code

The first line of the server program response is the status line. The status line starts with the HTTP version number, followed by three digits to indicate the response code, and finally is a readable response phrase. According to the first rule, the response can be divided into five categories:

Figure 6. Http response code

2. Difference Between get and post

 

8 methods are introduced in section 1.3. Get and post are the most basic and common methods. The differences between get and post methods in Form submission are summarized as follows:

  • Get gets data from the server, and post transfers data to the server.
  • Get
    Adds the parameter data queue to the URL referred to by the Action attribute of the submission form. The values correspond to each field in the form one by one, which can be seen in the URL. Post is implemented through HTTP
    Post mechanism: place each field in the form and its content in the body and send it to the URL address referred to by the Action attribute. You cannot see this process.
  • For the get method, the server uses request. querystring to obtain the value of the variable. For the POST method, the server uses request. Form to obtain the submitted data.
  • The size of data transmitted by get is small and cannot exceed 2 kb (this is mainly because the URL length is limited ). The amount of data transmitted by post is large, which is generally not restricted by default. However, theoretically, the limit depends on the server's processing capability.
  • Get
    Low Security and high post security. Because get data is stored in the request URL during transmission, many existing servers, proxy servers, or user proxies record the request URL
    Log on to the log file and place it in a certain place. In this way, some private information may be viewed by a third party. In addition, you can directly view the submitted data in the browser.
    In front of the user. All post operations are invisible to users.

If method is not specified during form submission, the default value is
GET request (. NET is post by default). The data submitted in form will be appended to the URL? Separated from the URL. The letter and digit are sent as is, but the space is converted to "+"
Other symbols are converted to % XX, where xx represents the ASCII (or ISO Latin-1) value of the symbol in hexadecimal notation.The data to be submitted for the GET request is placed in the HTTP Request Header, while the data to be submitted by post is placed in the object data. The data to be submitted by the get method can contain up to 2048 bytes, post does not have this restriction.
. The parameters passed by post are in the doc, that is, the text transmitted by the HTTP protocol. When accepted, the parameter section is parsed. Obtain parameters. Generally, it is better to use post. The data submitted by post is implicit. Get is passed in the URL to pass some data that does not need to be kept confidential. Get is passed through parameters in the URL, and post is not.

 

 

 

In addition, there is an in-depth keepalive mode for http: http://www.cnblogs.com/skynet/archive/2010/12/11/1903347.html

 

######################################## ################

######################################## ################

Note:

Check http-related content 1: I have a vague impression on HTTP. 2. Check that struts was blocked when the server responded to the request.

The HTTP protocol can be viewed as specifying the data formats of requests and responses (similar to interfaces). Different servers may have different implementations, however, the response content format must comply with the Protocol. In Java, the response output stream is obtained. The response content is returned to the client according to the setcontenttype, write, flush, and Close processes.

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.