HTTP request way Get and post differences in detail

Source: Internet
Author: User
Tags html header http post soap

http://blog.csdn.net/seeds_home/article/details/7881073

HTTP has two parts: request and response, sorted separately.

A HTTP request 1. HTTP request Format:

<request line>

<blank line>

[<request-body>]

In an HTTP request, the first line must be a request line, which describes the type of request, the resources to be accessed, and the HTTP version used. This is followed by a header section that describes the additional information that the server will use. After the header is a blank line, then you can add any additional data [called the body].

2. Get vs. Post differences

HTTP defines different ways to interact with the server, the most basic of which is get and post (development concerns only get requests and post requests).

The Get and Post methods have the following differences:

(1) On the client side, the Get method submits the data through the URL, the data can be seen in the URL, the Post method, and the data is placed within the HTML header submission.

(2) The data submitted by the Get method can only have up to 1024 bytes, while post does not have this limit.

(3) Security issues. As mentioned in (1), when you use GET, the parameters are displayed on the address bar, and post does not. So, if the data is in Chinese and is non-sensitive, then use get; If the user enters data that is not a Chinese character and contains sensitive data, then it is better to use post.

(4) Safe and idempotent. The so-called security means that the operation is used to obtain information rather than modify information. Idempotent means that multiple requests to the same URL should return the same result. The complete definition is not as strict as it seems. In other words, get requests generally should not have side effects. Fundamentally, the goal is that when a user opens a link, she can be confident that the resource has not changed from its point of view. For example, the front page of news sites is constantly being updated. Although the second request returns a different batch of news, the operation is still considered safe and idempotent, as it always returns the current news. Vice versa. The POST request is not that easy. Post represents a request that might change resources on the server. Still take the news site as an example, the reader's comments on the article should be implemented through the POST request because the site is different after the annotation is submitted (for example, an annotation appears below the article).


Examples of Get and post methods:

Get/books/?name=professional%20ajax http/1.1
Host:www.wrox.com
user-agent:mozilla/5.0 (Windows; U Windows NT 5.1; En-us; rv:1.7.6)
gecko/20050225 firefox/1.0.1
Connection:keep-alive


post/http/1.1
Host:www.wrox.com
user-agent:mozilla/5.0 (Windows; U Windows NT 5.1; En-us; rv:1.7.6)
gecko/20050225 firefox/1.0.1
content-type:application/x-www-form-urlencoded
Content-length:40
Connection:keep-alive
(----empty line here----)
Name=professional%20ajax&publisher=wiley


3. The differences between get and post methods in form submissions are summarized as follows:

(1) Get gets data from the server and post is the data that is sent to the server.

(2) For the form submission method, the server side can only use Request.QueryString to get the data submitted by the Get method, the data submitted by post can only be obtained by Request.Form.

(3) In general, try to avoid using get to submit the form, as it may lead to security issues. For example, in the login form with get, the user entered the user name and password will be exposed in the address bar. However, in a paging program, it is better to use get mode than post.


Two HTTP response
1. HTTP response Format:

<status line>


<blank line>

[<response-body>]

The only real difference in response is that the first line uses state information instead of the request information. Status line describes the requested resource situation by providing a status code.

HTTP Response instance:

http/1.1 OK
Date:sat, Dec 2005 23:59:59 GMT
Content-type:text/html;charset=iso-8859-1
content-length:122
<title> Wrox Homepage </title>
<body>
!--body goes here-->
</body>
2. The most commonly used status codes are:

(OK): The resource was found and everything is OK.
304 (not MODIFIED): The resource has not been modified since the last request. This is commonly used for browser caching mechanisms.
401 (Unauthorized): The client does not have permission to access the resource. This usually causes the browser to require the user to enter a user name and password to log on to the server.
403 (FORBIDDEN): Client failed to get authorization. This is usually followed by an incorrect user name or password that was entered after 401.
404 (Not FOUND): The requested resource does not exist at the specified location.


The HTTP GET,POST,SOAP protocol is all running on HTTP.
1) Get: The request parameter is appended to the URL as a sequence of key/value pairs (query string)
The length of the query string is limited by the Web browser and Web server (ie supports up to 2048 characters) and is not suitable for transferring large datasets
At the same time, it's not safe.
2) Post: The request parameter is transmitted in a different part of the HTTP header (named entity body), which is used to transfer the form information and must be
The Content-type is set to: application/x-www-form-urlencoded.
The post is designed to support user fields on Web Forms, and its parameters are also transmitted as key/value.
However: it does not support complex data types, because post does not define the semantics and rules for transferring data structures.
3) Soap: is a dedicated version of HTTP POST, followed by a special XML message format
Content-type set to: Text/xml
Any data can be XML


The difference between HTTP post and get

1, HTTP only post and get two kinds of command mode;

2, POST is designed to put things up, and get is designed to take things from the server, get can also be able to send less data to the server, and get can also transfer data, just to design tell the server, you need what kind of data. The post information is the content of the HTTP request, and get is transmitted over the HTTP header;

3, post and get in HTTP in different ways, get parameters are transmitted in the head of the HTTP, and the post data is sent in the content of the HTTP request;

4, post transfer data, do not need to display in the URL, and get method to display in the URL;

5, the Get method is limited by the URL length, can only pass about 1024 bytes, the data volume of the post transmission is large, can reach 2 m, and according to Microsoft, Microsoft to use Request.Form () can receive the maximum data is limited, IIS 4 is a KB byte, IIS 5 is in the KB byte;

6, SOAP is dependent on the HTTP post mode implementation;

Example:

HTTP GET

Send

Get/demowebservices2.8/service.asmx/cancelorder? Userid=string&pwd=string&orderconfirmation=string http/1.1
Host:api.efxnow.com

Reply

http/1.1 OK
Content-type:text/xml; Charset=utf-8
Content-length:length

<?xml version= "1.0" encoding= "Utf-8"?>
<objplaceorderresponse xmlns= "https://api.efxnow.com/webservices2.3" >
<Success>boolean</Success>
<ErrorDescription>string</ErrorDescription>
<ErrorNumber>int</ErrorNumber>
<CustomerOrderReference>long</CustomerOrderReference>
<OrderConfirmation>string</OrderConfirmation>
<CustomerDealRef>string</CustomerDealRef>
</objPlaceOrderResponse>


HTTP POST

Send

Post/demowebservices2.8/service.asmx/cancelorder http/1.1
Host:api.efxnow.com
content-type:application/x-www-form-urlencoded
Content-length:length

Userid=string&pwd=string&orderconfirmation=string

Reply

http/1.1 OK
Content-type:text/xml; Charset=utf-8
Content-length:length

<?xml version= "1.0" encoding= "Utf-8"?>
<objplaceorderresponse xmlns= "https://api.efxnow.com/webservices2.3" >
<Success>boolean</Success>
<ErrorDescription>string</ErrorDescription>
<ErrorNumber>int</ErrorNumber>
<CustomerOrderReference>long</CustomerOrderReference>
<OrderConfirmation>string</OrderConfirmation>
<CustomerDealRef>string</CustomerDealRef>
</objPlaceOrderResponse>


SOAP 1.2

Send

Post/demowebservices2.8/service.asmx http/1.1
Host:api.efxnow.com
Content-type:application/soap+xml; Charset=utf-8
Content-length:length

<?xml version= "1.0" encoding= "Utf-8"?>
<soap12:envelope xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd= "http://www.w3.org/2001/ XmlSchema "xmlns:soap12=" Http://www.w3.org/2003/05/soap-envelope ">
<soap12:Body>
<cancelorder xmlns= "https://api.efxnow.com/webservices2.3" >
<UserID>string</UserID>
<PWD>string</PWD>
<OrderConfirmation>string</OrderConfirmation>
</CancelOrder>
</soap12:Body>
</soap12:Envelope>

Reply

http/1.1 OK
Content-type:application/soap+xml; Charset=utf-8
Content-length:length

<?xml version= "1.0" encoding= "Utf-8"?>
<soap12:envelope xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd= "http://www.w3.org/2001/ XmlSchema "xmlns:soap12=" Http://www.w3.org/2003/05/soap-envelope ">
<soap12:Body>
<cancelorderresponse xmlns= "https://api.efxnow.com/webservices2.3" >
<CancelOrderResult>
<Success>boolean</Success>
<ErrorDescription>string</ErrorDescription>
<ErrorNumber>int</ErrorNumber>
<CustomerOrderReference>long</CustomerOrderReference>
<OrderConfirmation>string</OrderConfirmation>
<CustomerDealRef>string</CustomerDealRef>
</CancelOrderResult>
</CancelOrderResponse>
</soap12:Body>

</soap12:Envelope>

HTTP request way Get and post differences in detail

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.