HTTP POST get__ Network programming

Source: Internet
Author: User
Tags html header http post soap representational state transfer
One principle Difference
Generally in the browser to enter the URL access resources are through the get way,
in form submission, you can specify the way to submit by using method for Get or post, the default is to submit

HTTP defines different methods of interacting with the server, and the most basic methods are 4 kinds, namely Get,post,put,delete

Here, you should have a general understanding, get is generally used to obtain/query resource information, and post is generally used to update resource information (personally think that this is the essential difference between get and post, but also the intention of the Protocol designers, the other differences are specific manifestations of differences).

According to the HTTP specification, get is used for information acquisition, and should be secure and idempotent.

1. The so-called security means that the operation is used to obtain information rather than modify information. In other words, get requests should not generally have side effects. That is, it simply gets the resource information, like a database query, that does not modify, adds data, and does not affect the state of the resource.

* Note: The meaning of security here is simply to modify information.

2. Idempotent means that multiple requests to the same URL should return the same result.

But in practical applications, the above 2 provisions are not so strict. Cite examples of other people's articles: for example, the front page of a news site is constantly 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. Fundamentally, if the goal is when a user opens a link, he can be sure that from his point of view there is no change in resources.

According to the HTTP specification, post represents a request that might modify a resource on a variable server. Continue to cite the example above: or the news to the website, for example, readers of the news to publish their own comments should be implemented by post, because the site after the comments submitted resources are different, or the resources have been modified.

It probably says some of the original reason questions about Get and post in the HTTP specification. But in practice, many people do not follow the HTTP specification, which causes many reasons for this problem, such as:

1. Many people are greedy for convenience, update the resource with GET, because the post must be to form (form), this will be a bit of trouble.

2. The increase of resources, delete, change, check operation, in fact, can be completed through the get/post, do not need to use put and delete.

3. Another is that early but web MVC framework designers have not consciously viewed and designed URLs as abstract resources. A more serious problem is that the traditional Web MVC framework basically supports both get and post two HTTP methods, not the put and delete methods.

The above 3 points typically describe the old style (no strict adherence to the HTTP specification), and as the architecture progresses, there is now rest (representational state Transfer), a new style of support for HTTP specifications, not to mention here, refer to the RESTful Web Services. Two expression form differences

Figuring out the difference between the two principles, let's take a look at the difference in their actual application:

To understand the difference in the transmission process, let's look at the format of the HTTP protocol:

HTTP request:
<request line>          //http request line

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].

Get and Post Method instance:

Get/books/?sex=man&name=professional 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----)
name=professional%20ajax&publisher= Wiley

With the above understanding and examples of HTTP requests, let's look at the differences between the two submissions:

(1) Get submit, the requested data will be appended to the URL (that is, put the data in the HTTP protocol header), to split the URL and transfer data, multiple parameters with & connection; for example: login.action?name=hyddd&password= Idontknow&verify=%e4%bd%a0%E5%A5%BD. If the data is an English letter/number, sent as is, if it is a space, converted to +, if it is Chinese/other characters, the string is directly encrypted with BASE64, such as:%E4%BD%A0%E5%A5%BD, where the xx in%xx for the symbol in the 16 in ASCII representation.

Post submission: The submitted data is placed in the package body of the HTTP package. The red font in the example above indicates the actual transfer data

Therefore, the data submitted by get is displayed in the Address bar, and post submission, the Address bar does not change

(2) The size of the transmitted data: first of all, the HTTP protocol does not limit the size of the data transmitted, nor does the HTTP protocol specification limit the length of the URL.

And in the actual development of the main limitations are:

Get: Specific browsers and servers have restrictions on the length of URLs, such as IE's limit of 2083 bytes (2k+35) for URL lengths. For other browsers, such as Netscape, Firefox, etc., there is no theoretical length limit, the limit depends on the operating system support.

So for get commits, the transfer data is limited by the length of the URL.

POST: Theoretically, the data is not restricted because it is not passed through a URL. However, the actual Web server will specify the size of the post submission data limits, Apache, IIS6 have their own configuration.

(3) Security:

Post is more secure than get. Note: The security described here is not the same concept as the "security" mentioned above. The meaning of the above "security" is simply not to make data modifications, and here the meaning of security is the meaning of the real, for example: to submit data through get, user name and password will be clear on the URL, because (1) login page is likely to be cached by the browser, (2) Other people to view the history of the browser, Then others can get your account number and password, in addition, use get submit data may also cause Cross-site request forgery attack

(4) 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 while it is unsafe
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 the Content-type must be 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 three HTTP response

1. HTTP response Format:

<status line>          //http response status line

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:12 2    Wrox homepage   !--body goes here--> 
   

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. Four complete Example:

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>

This article turns from: http://hi.baidu.com/eveready/blog/item/585bbb30fbcee915eac4af27.html

Get is getting data from the server, and post is transferring data to the server.
Get and post are just a way of passing data, and getting can upload data to the server, and their essence is to send requests and receive results. There is a difference between the organization format and the amount of data, which is described in the HTTP protocol

Get is to add the parameter data queue to the URL that refers to the action attribute of the submission form, and the value corresponds to each field one by one in the form, as you can see in the URL. Post is the HTTP post mechanism that places the fields in the form and their contents in the HTML header to the URL address that the action attribute refers to. This process is not visible to the user.
Because get is designed to transmit small data, and it is best not to modify the server data, so the browser is generally in the address bar can be seen, but post is generally used to pass large data, or compare the privacy of the data, so in the address bar see, can not see the agreement is not stipulated, is the browser.

For Get mode, the server end uses Request.QueryString to obtain the value of the variable, and for the Post method, the server end uses Request.Form to obtain the submitted data.
Don't understand, how to get the variable and your server-related, and not get or post, the server has to do the encapsulation of these requests

The amount of data transferred by get is small and cannot be greater than 2KB. Post transfers have a large amount of data, which is generally default to unrestricted. In theory, however, the maximum number of IIS4 is 100KB in 80KB,IIS5.
Post basically no limit, I think we all uploaded files, are the post way. It's just that you want to modify the type parameter inside the form to get a very low security and high post security.
If there is no encryption, they are the same level of security, any listener can be all the data to listen to, do not trust yourself next monitor network resources software,

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.