Why GET method is faster than POST in HTTP?

2019-01-08 16:19发布

I am just new to web programming and just curious to know abt Get and Post methods of sending data from one page to another page.

It is said that Get method is faster than Post but i don't know why is it one reason i could find is that Get can take only 255 chars with it? Is there any other reasons , please someone explain me?

标签: http post get
9条回答
beautiful°
2楼-- · 2019-01-08 16:45

It's not much about speed. There are plenty of cases where POST is more applicable. For example, search engines will index GET URLs and browsers can bookmark them and make them show up in history. As a result, if you take actions like modifying a DB based on a GET request, it might be harmful as some bots might also traverse the URL.

The other case can be security issue. If you post credentials using GET, it'll get listed in browser history and server log files.

查看更多
女痞
3楼-- · 2019-01-08 16:47

Looking at the http protocol, POST or GET should be equally easy and fast to parse. I would argue, there is no performance difference.

Take a look at the raw HTTP headers

http GET

GET /index.html?userid=joe&password=guessme HTTP/1.1
Host: www.mysite.com
User-Agent: Mozilla/4.0

http POST

POST /login.jsp HTTP/1.1
Host: www.mysite.com
User-Agent: Mozilla/4.0
Content-Length: 27
Content-Type: application/x-www-form-urlencoded

userid=joe&password=guessme

From my point of view, performance should not be considered when comparing GET and POST.

查看更多
Evening l夕情丶
4楼-- · 2019-01-08 16:48

Just my few cents from 2016.

I am creating a simple message system. At first I used POST to receive new alerts. In jQuery I had:

$.post('/a/alerts', 'stamp=' + STAMP, function(result)
{
});

And in PHP I used $_POST['stamp']. Even from localhost I got 90-100 ms for every request like this. I simply changed:

$.get('/a/alerts?stamp=' + STAMP, function(result)
{
});

and in PHP switched to $_GET['stamp']. So a little less than 1 minute of changes. Now every request takes 30-40 ms.

So GET can be twice as fast as POST. Of course not always but for small amounts of data I get same results all the time.

查看更多
欢心
5楼-- · 2019-01-08 16:48

GET is slightly faster because the values are sent in the header unlike the POST the values are sent in the request body, in the format that the content type specifies.

Usually the content type is application/x-www-form-urlencoded, so the request body uses the same format as the query string:

parameter=value&also=another When you use a file upload in the form, you use the multipart/form-data encoding instead, which has a different format. It's more complicated.

查看更多
时光不老,我们不散
6楼-- · 2019-01-08 16:48

POST will grow your headers more, just making it larger, but the difference ought to be negligible really, so I don't see why this should be a concern.

Just bear in mind that the proper way to speak HTTP is to use GET only for actions and POST for data. You don't have to, but you also don't want to have a case where Google bots can, for example, insert, delete or manipulate data that was only meant for a human to handle simply because it is following the links it finds.

查看更多
We Are One
7楼-- · 2019-01-08 16:56

Another thing about http post is it can be 2 calls when the http header Expect: 100-Continue is used. First browser sends the http post headers and server replies with “HTTP 100 Continue”. When browser receives this, it sends the actual body.

http://omaralzabir.com/atlas_2__http_post_is_slower_and_it_s_default_in_atlas/

I think this is the answer that the author was looking for.

查看更多
登录 后发表回答