What is the fundamental difference between POST and GET?

Source: Internet
Author: User
What is the fundamental difference between POST and GET? (Please do not answer the question of POST security or the large size of information transmitted by POST.) Please analyze the difference between POST and GET from the perspective of packet packets. Thank you.
  1. What is the fundamental difference between POST and GET? (Please do not answer questions about POST security or the large size of information transmitted by POST)
  2. Analyze the difference between POST and GET from the perspective of packet packets

Thank you.

Reply content:
  1. What is the fundamental difference between POST and GET? (Please do not answer questions about POST security or the large size of information transmitted by POST)
  2. Analyze the difference between POST and GET from the perspective of packet packets

Thank you.

From the perspective of RESTful:
1. GET is the query resource, and POST is the Add Resource.
2. idempotence.
GET, PUT, and DELETE are all idempotent operations.
POST is not.
For details, you can google a restful article. Ruan Yifeng this can also look at: http://www.ruanyifeng.com/blog/2011/09/restful.html

From the Protocol perspective, POST and GET methods are different only for the first line of the message. GET can also carry CONTENT-BODY

In addition, post can also receive query strings. The simplest example is


 
  
 

Get can also have a body. In the Protocol, only the server does not need to care about the get body (it can be included with the consent), but it is not allowed to carry it in plain text. Some people in the comments also mentioned the elasticsearch chestnuts.

The semantics and power of get post are different. I think it is beyond the scope of the Protocol or the owner wants to capture packets.

Previously, the concepts of restful are all very clear. Here I add that the following is a get request. I am too lazy to capture packets and copy them directly on the chrome console, I can tell you the essential difference from the analysis of packets
I think the essential difference between get and post is the difference between where parameters are put,

Get is placed in the header (so the length is limited, it is the browser's limit on the url length), post is placed in the body (there is no limit on the length ),

If you ask me what is the difference between the header and the body, I can only Haha (we recommend you capture the packet). Both are tcp data streams, and the header and body are separated by/r/n.

get  Remote Address:222.186.132.183:80Request URL:http://qiniu-plupload.qiniudn.com/bb.png?imageView2/1/w/100/h/100Request Method:GETStatus Code:200 OKResponse Headersview sourceAccept-Ranges:bytesAccess-Control-Allow-Origin:*Access-Control-Max-Age:2592000Cache-Control:public, max-age=31536000Connection:keep-aliveContent-Length:15509Content-Type:image/pngDate:Wed, 29 Apr 2015 07:01:08 GMTETag:"ALCDKnR1WgNfUxiMBRwEuXoe76OQ"Server:nginx/1.4.4X-Log:mc.g/404;mc.g:2;RS:2;mc.s;DC/404;FOPDC/404;FOPAGENT;IMAGE:239;FOPAGENT:240;FOPAGENT;IMAGE:239;FOPAGENT:240;FOPG:241;FOPAGENT;IO:249X-Qiniu-Zone:0X-Reqid:YVQAABBhtnn3adkTX-Via:1.1 tzh57:8110 (Cdn Cache Server V2.0), 1.1 zhenjiang157:10 (Cdn Cache Server V2.0)X-Whom:nb263Request Headersview sourceAccept:image/webp,*/*;q=0.8Accept-Encoding:gzip, deflate, sdchAccept-Language:zh-CN,zh;q=0.8Cache-Control:no-cacheConnection:keep-aliveHost:qiniu-plupload.qiniudn.comPragma:no-cacheRA-Sid:DE49CAE2-20141215-034718-ab4eeb-10884dRA-Ver:2.10.0Referer:http://jssdk.demo.qiniu.io/User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36Query String Parametersview sourceview URL encodedimageView2/1/w/100/h/100:
Remote Address:183.136.139.10:80Request URL:http://up.qiniu.com/Request Method:POSTStatus Code:200 OKResponse Headersview sourceAccess-Control-Allow-Headers:X-File-Name, X-File-Type, X-File-SizeAccess-Control-Allow-Methods:OPTIONS, HEAD, POSTAccess-Control-Allow-Origin:*Access-Control-Max-Age:2592000Cache-Control:no-store, no-cache, must-revalidateConnection:keep-aliveContent-Length:54Content-Type:application/jsonDate:Wed, 29 Apr 2015 07:01:08 GMTPragma:no-cacheServer:nginx/1.4.4X-Content-Type-Options:nosniffX-Log:s.ph;s.put.tw;s.put.tr:5;s.put.tw:1;s.put.tr:4;s.ph;s.put.tw:1;s.put.tr:5;s.ph;PFDS:12;PFDS:13;PFDS:14;rdb.g/no such key;DBD/404;DBG/404;v4.exist:1/Document not found;rs12_9.ins;qtbl.ins:2;mc.s;RS:3;rs.put:4;rs-upload.putFile:20;UP:27X-Reqid:-zwAABHcpXL3adkTRequest Headersview sourceAccept:*/*Accept-Encoding:gzip, deflateAccept-Language:zh-CN,zh;q=0.8Cache-Control:no-cacheConnection:keep-aliveContent-Length:620773Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryb5PfXDf4M1oCl5QMHost:up.qiniu.comOrigin:http://jssdk.demo.qiniu.ioPragma:no-cacheRA-Sid:DE49CAE2-20141215-034718-ab4eeb-10884dRA-Ver:2.10.0Referer:http://jssdk.demo.qiniu.io/User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36Request Payload------WebKitFormBoundaryb5PfXDf4M1oCl5QMContent-Disposition: form-data; name="name"bb.png------WebKitFormBoundaryb5PfXDf4M1oCl5QMContent-Disposition: form-data; name="chunk"0------WebKitFormBoundaryb5PfXDf4M1oCl5QMContent-Disposition: form-data; name="chunks"1------WebKitFormBoundaryb5PfXDf4M1oCl5QMContent-Disposition: form-data; name="key"bb.png------WebKitFormBoundaryb5PfXDf4M1oCl5QMContent-Disposition: form-data; name="token"0MLvWPnyya1WtPnXFy9KLyGHyFPNdZceomLVk0c9:d5M0tc6IYvvXMsWeqXN-_cJHEd0=:eyJzY29wZSI6InFpbml1LXBsdXBsb2FkIiwiZGVhZGxpbmUiOjE0MzAyOTQ0NDd9------WebKitFormBoundaryb5PfXDf4M1oCl5QMContent-Disposition: form-data; name="file"; filename="bb.png"Content-Type: image/png------WebKitFormBoundaryb5PfXDf4M1oCl5QM--

I think the essential difference between get and post is the difference between where parameters are put,

Get is placed in the header (so the length is limited, it is the browser's limit on the url length), post is placed in the body (there is no limit on the length ),

The post I post here is in form-data format,

Many people mix the x-www-form-urlencoded method in post with the get request, because on the server side, many language frameworks obtain parameters for these two requests in almost the same way.

Next, let's take a look at the x-www-form-urlencoded method.


POST http://www.example.com HTTP/1.1Content-Type: application/x-www-form-urlencoded;charset=utf-8title=test&sub%5B%5D=1&sub%5B%5D=2&sub%5B%5D=3

This article is very clear.

The subject raised this question because many people now use GET to submit data. In terms of protocol specifications, This is a clever (or lazy) approach. Because GET was originally designed to GET data (the HTTP protocol states that the GET and HEAD methods should only GET resources rather than execute actions ). However, GET is easy to use. To use POST, you need to create a form on the webpage, which is relatively troublesome.
For example, POST is a pen designed for writing. GET is a lipstick, not designed for writing, but sometimes used for writing.
However, we still need to point out that using GET instead of POST is not a good habit. Because the GET operation may be cached incorrectly by some poorly designed systems, this will cause the corresponding request not to be executed. In addition, replacing POST with GET is also prone to XSS problems.

In terms of HTTP protocol specifications, xelz has already answered. The HTTP protocol does not explicitly indicate that GET does not allow a message body (it does not seem to have been checked for a while, please note if there is an error), but it does not define any function of the GET message body. Therefore, the Web server can correctly process the GET request with a message body, but the message experience is ignored.

This may be more or less of a RESTful credit. POST/DELETE/PUT/GET correspond to data operations, and there are a lot of online materials.

POST/uri create DELETE/uri/xxx delete put/uri/xxx update or create GET/uri/xxx View

In addition, the URL has a length limit (although it is very long, but sometimes it is not necessarily enough)

Let's take a look at the link description of this article.

I recommend that you read two articles. The first one is more popular than the second one. The second one is later about some http protocol. In fact, their differences are the same.
What is the difference between GET and POST?
HTTP POST GET

Get 10 thousand times get the same thing. post is different. This is the idempotent and non-idempotent power.

GET and POST relationship

The essential difference is where data is stored.

The difference between properties is idempotence.

My understanding:
POST submission is implicit. (The submitted parameters are hidden for traffic runners)
GET submission is explicit. (The submitted parameters are included in the URL and are visible)

If you have to say different, the browser processes the two protocols in different ways. If GET wants to refresh several times, the POST refresh will prompt "repeat the form ", if you have to give these two hats, it should be based on the conventional habits that these two things have different "idempotence.

It is hard to say whether POST and GET operations are different in the background.
It seems that I have tried it before. jsp servlet. getParameter cannot get the parameter of POST placed in URL. I'm not sure.

  1. There is no BODY, that is, there is no information BODY except the URL and the header is the fundamental difference. Therefore, GET cannot be used to transmit a large amount of data from the client to the server. Because all GET parameters are in the URL (browser address bar.
  2. HTTP is an application layer protocol, which is generally based on TCP reliable data streams. Therefore, the analysis of HTTP does not require analysis of packets and packets.

Example:
GET method:
GET/index.html? Name = leo HTTP/1.1
Accept:/ <这是头部>
<空行>
End

POST method:
POST/index.html http/ 1.1
Acept:/
Content-Length: 10
<空行>
1234567890
<空行>
End

When capturing packets, you can find that:
Get usually has one to two tcp packets (the Information header and data are all together, if there are many information headers, two or more packets will be generated ), the post must have at least two packages (the first package is the information header and the second is the data ).

Ah, you have nothing to do every day. This problem makes it clear what help is there for development? The program is used to solve the problem. You are purely engaged in theoretical research. Anyway, I am an ignorant and fearless. I can't finish it, and I can use it all well, you can skip this process for ten years. Finally, there are no application scenarios yet.

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.