Get and Post format parsing for HTTP

Source: Internet
Author: User

This article from Csdn Blog, reproduced please indicate the source: http://blog.csdn.net/yc0188/archive/2009/10/29/4741871.aspx

HTTP messages are text-oriented, and each field in the message is a number of ASCII strings, and the length of each field is indeterminate. HTTP has two types of messages: Request messages and response messages.
Request message
An HTTP request message consists of a request line, a request header (header), a blank line, and 4 parts of the request data, giving the general format of the request message.


(1) Request line
The request line consists of 3 fields of the Request Method field, the URL field, and the HTTP protocol version field, separated by a space. For example, get/index.html http/1.1.
The HTTP protocol request method has get, POST, HEAD, PUT, DELETE, OPTIONS, TRACE, CONNECT. The most common get methods and post methods are described here.
Get: Use the Get method when the client wants to read the document from the server. The Get method requires the server to place the URL-positioned resource in the data portion of the response message, which is sent back to the client. When using the Get method, the request parameter and the corresponding value are appended to the URL, using a question mark ("?" ) represents the end of the URL and the start of the request parameter, which is limited by the length of the pass parameter. For example,/index.jsp?id=100&op=bind.
Post: You can use the Post method when the client provides more information to the server. The Post method encapsulates the request parameters in the HTTP request data, appears as a name/value, and can transmit large amounts of data that can be used to transfer files.
(2) Request head
The request header consists of a keyword/value pair, one pair per line, a keyword and a value separated by a colon ":". The request header notifies the server that there is information about the client request, and the typical request headers are:
User-agent: The type of browser that generated the request.
Accept: A list of content types that the client can identify.
Host: The hostname of the request, which allows multiple domain names to be located in the same IP address as the virtual host.
(3) Blank line
The last request header is followed by a blank line that sends a carriage return and a newline character, notifying the server that the request header is no longer available.
A blank line is required for a full HTTP request, otherwise the server will assume that the requested data has not been fully sent to the server and is in a waiting state.
(4) Request data
The request data is not used in the Get method, but is used in the Post method. The Post method is useful for situations where a customer needs to fill out a form. The most commonly used request headers associated with request data are Content-type and content-length.
(5) Sample Request
POST:
The post headers are as follows:

post/sn/index.php http/1.1
Accept: */*
Accept-language:zh-cn
Host:localhost


content-type:application/x-www-form-urlencoded
Content-length:12
Connection:close
Sn=123&n=asa
There is a blank line behind the HTTP header, and the post data is sent behind the empty line, and the length is passed Content-length:12
Indicates that this post data contains two
Sn=123
N=asa
Where: content-type:application/x-www-form-urlencoded Specifies the encoding type of the post data
Content-length:12 the length of the post data
GET:
The Get report has the following headers:
Get/sn/index.php?sn=123&n=asa http/1.1
Accept: */*
Accept-language:zh-cn
Host:localhost


content-type:application/x-www-form-urlencoded
Content-length:12
Connection:close

Get and Post format parsing for HTTP

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.