the difference between get and post of HTTP request methodTags: soap server encodingwindowsurl browser 2012-08-18 16:24 937 people read comments (0) Favorites Report Category: Web Applications (3)
Copyright NOTICE: This article is the original article, without the owner's permission to reprint.
Directory (?) [+]
HTTP consists of two parts: request and response, sorted separately below. one. 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 resource to be accessed, and the HTTP version used. This is followed by a header (header) section that describes the additional information that the server will use. After the header is a blank line, after which you can add any additional data [called the body]. 2. Get vs Post Difference
HTTP defines different methods of interacting with the server, the most basic of which is get and post (development concerns only get requests and post requests).
get and Post methods have the following differences:
(1) At the client, the Get mode submits the data through the URL, the data can be seen in the URL; Post mode, the data is placed in the HTML header to submit.
(2) The data submitted by Get method can only have up to 1024 bytes, while post does not have this limit.
(3) Security issues. As mentioned in (1), when using get, the parameters are displayed on the address bar, and the post does not. So, if the data is Chinese and is not sensitive, use get, or use post if the user enters data that is not a Chinese character and contains sensitive data.
(4) Safe and idempotent. The so-called safe 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 should not generally have side effects. Fundamentally, the goal is that when a user opens a link, she can be sure that it doesn't change resources from its perspective. For example, the front pages of news sites are 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. Post requests are not that easy. Post represents a request that might change resources on the server. Still, for example, a news site, the reader's note to the article should be implemented through a POST request, because the site has changed after the annotation was submitted (for example, an annotation appears below the article).
Get and Post Method instance:
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
(----a blank line here----)
Name=professional%20ajax&publisher=wiley
3. The difference between get and post in form submission is summed up in the following ways:
(1) Get is to obtain data from the server, post is to send data to the server.
(2) For the form of submission, the server can only use Request.QueryString to get the data submitted by the way, post the data submitted only with Request.Form to obtain.
(3) Generally, avoid submitting forms using get methods, as it is possible to cause security problems. For example, in the landing form in the get way, the user entered the user name and password will be exposed in the address bar. In a paging program, however, it is better to use get than to 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 replaces the request information with state information. The status line indicates the requested resource condition by providing a status code.
HTTP Response instance:
http/1.1 OK
Date:sat, Dec 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): Found the resource, and everything is OK.
304 (not MODIFIED): The resource has not been modified since the last request. This is commonly used for caching mechanisms in browsers.
401 (Unauthorized): The client is not authorized 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 obtain authorization. This is usually followed by an incorrect user name or password entered after 401.
404 (Not FOUND): The requested resource does not exist at the specified location.
The HTTP GET,POST,SOAP protocol is run on HTTP
1 Get: The request parameter is appended to the URL as a sequence of key/value pairs (the 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 transporting large datasets
Meanwhile, 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, so you must
Content-type set to: application/x-www-form-urlencoded.
Post design is used to support user fields on Web Forms, and their parameters are also transferred as Key/value.
However: it does not support complex data types because post does not define the semantics and rules of the transport data structure.
3 soap: is a special 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 an HTTP post and a 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, getting can also send less data to the server, and get is also able to transmit data, only to design to tell the server, you really 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 the way of HTTP transmission, get parameters are transmitted in the head of HTTP, and post data is sent in the content of the HTTP request;
4, post transmission data, do not need to be displayed in the URL, and get method to display in the URL;
5, get method is limited by the URL length, can only pass about 1024 bytes; The post transmits a large amount of data that can reach 2 m, and according to Microsoft, Microsoft is limited to the maximum data that can be received with Request.Form (), IIS 4 is KB byte, IIS 5 Medium 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>