16872

POST vs GET methods - at the network level, which is more impacted by latency?

Is there any difference in network communication for HTTP GET and POST requests?

With GET, I understand that the entire request is sent in one go. With POST, I think the initial request is sent, and then a second request is sent which sends all the parameters.

For example, assume that the latency between server and client is 500ms. What would be the total time for a GET vs POST call?

Answer1:

The packets are all TCP packets, which carry the HTTP protocol, the request method doesn't change the network layer's response time.

It will change on request-to-request basis depending on the size of a request, but that's not determined by the request type.

You can send more data with post than get, but this doesn't mean they respond faster, it's a separate issue.

The speed at which the HTTP server can process and return a result is on the server you're using, and likely to be so negligible it's not worth mentioning.

The speed at which the result comes back from the server depends on what resource the HTTP server is processing, if it's calling a PHP file that takes time, then it's going to take time...

There isn't a clear difference in the packets... this is a GET request over SSL:

00907f8252f7001e4fe86a93080045000028 0bb2400080067380ac100167adc22064c51a 01bb66ccad148448d84850103f05bde90000

And this is a POST request over SSL:

00907f8252f7001e4fe86a93080045000028 0c0640008006732cac100167adc22064c511 01bbe538c0df8621dc6150104042248c0000

There isn't exactly a lot of involvement of whether the string inside the TCP packet is "GET" or "POST," the network looks at it, says "oh, you're TCP, Huh? Well, off you go then." It doesn't care.

Any delay outside of normal network traffic is soley due to processing on the sever level, or on the code it's working through.

Answer2:

POST requests have edge due to less logging

Given the same amount of information (the POST message doesn't exceed the GET), POST should technically be faster on the serverside (by nano-to-picoseconds):

    <li>Generally web servers, like Apache, log the requests somewhere</li> <li>

    POST requests do not log the query string, thus less write processing. Server IOPS may inadvertently affect latency

    <strong>Without this, given the same packets, they're practically equivalent.</strong> The GET stores data in the query string, the POST stores the info in the message body. The server processes both, just in different ways.

    </li> </ul>

    On the client side, the POST requires more processing to prepare the message. You'll notice this if doing any AJAX, it's a lot easier to send a GET request than POST.

    GET has the ability to outperform POST requests

    <ol> <li>

    As defined by w3 on HTTP/1.1, the GET has the ability to perform a partial request, thus limiting the network bandwidth:

    The semantics of the GET method change to a "partial GET" if the request message includes a Range header field. A partial GET requests that only part of the entity be transferred, as described in section 14.35. The partial GET method is intended to reduce unnecessary network usage by allowing partially-retrieved entities to be completed without transferring data already held by the client.

    </li> <li>

    Additionally, w3 describes a conditional GET to reduce network usage:

    The semantics of the GET method change to a "conditional GET" if the request message includes an If-Modified-Since, If-Unmodified-Since, If-Match, If-None-Match, or If-Range header field. A conditional GET method requests that the entity be transferred only under the circumstances described by the conditional header field(s). The conditional GET method is intended to reduce unnecessary network usage by allowing cached entities to be refreshed without requiring multiple requests or transferring data already held by the client.

    </li> <li>GET requests are cacheable. This reduces network bandwidth because a browser may see a request that has already been made in the past, which isn't expired yet and responds by a seemingly instantaneous response from cache.</li> </ol>

    Answer3:

    For a given piece of data, they will likely be very nearly the same. Here is what a GET request may look like:

    GET /test?x=5&y=3&z=4 HTTP/1.1 Header1: value Header2: value ...

    Here is how the same would look as a POST:

    POST /test HTTP/1.1 Header1: value Header2: value ... x=5&y=3&z=4

    So it's the same amount of data. The real question is whether you want the user to be able to bookmark and return to the URL and see the same data again in the future. GETs are used for that, POSTs are used for requesting data be changed on the server, or for security reasons (don't use GET to submit a password, for example).

    Answer4:

    Jonathan's answer is very elucidative. But let me go a little further on the spot where requests differ from each other.

    All information flowing through internet goes through small packages. Let's say each package has a max capacity of 1KB (this is not the correct value, it's just for clarification on the mechanism, if you want real values about limits go search on RFC's).

    OK, so we have a GET and a POST request. The packages are very similar as ilustrated by Jonathan. In that case, with a small amount of data, everything can be wrapped inside the 1KB package, thus there are no differentce on the network performance.

    But what if the request needs to be huge? A few people know, but there is a max length for a GET request which may vary by server. Try ask any site.com/foo/a{200 times A}. It will return an invalid/bad request, instead of just a 404 not found.

    So here is where POST takes place. If data amount is bigger than a certain value, POST allows the server to continue listing to that request and parse the values.

    Also there is another underlying difference in the behavior that wasn't mentioned before. POST data is parsed within browser to the current document encoding before being sent to the server.

    Answer5:

    I tested this while monitoring in Wireshark.

    I created a simple HTML form and toggled the method between GET and POST.

    Consistently, I noticed that GET requests send one packet, while POST sends two. Even when the form data is very small, the POST data is always sent in the second packet.

    This suggests to me that POST would be more impacted by latency.

    <strong>UPDATE 2011.07.05:</strong>

    Here is the simple HTML form for POST:

    <form method="GET" action="/form-handler.aspx"> <input type="hidden" value="12345" /> <input type="submit" value="click to submit" /> </form>

    Here is the POST version:

    <form method="POST" action="/form-handler.aspx"> <input type="hidden" value="12345" /> <input type="submit" value="click to submit" /> </form>

    Answer6:

    Its all about implementation on client side. In http specs there is no such condition. Time to send depends on amount of data. If you use POST only to replace GET it will be indistinguishably.

Recommend

  • Is possible to disable Javascript/Jquery from the browser inspector console?
  • Thousands separators in Ext.form.NumberField
  • HttpCore for measuring http request/response elapsed time
  • Javascript setting Date to previous year from the current year [closed]
  • SpringBoot TestRestTemplate and LocalDateTime not working
  • How do I link the environment variable PACKAGE_DIRS to my local, private packages?
  • Can some data be separated in a Tcp connection?
  • How can I validate a date including “00:07 PM” in JavaScript?
  • Why is this jQuery reference '$(“”)' instead of '$(“”)'?
  • SQL Azure SPLIT AT Backend Process and Resource Throttling
  • Sql indexes vs full table scan
  • limited threads in soapUI free version
  • Class implementation in a header file == bad style? [duplicate]
  • Get all existing pointers to an object
  • Send emails through VB6 if no email client
  • iOS Cordova first plugin - plugin.xml to inject a feature
  • Access user's phone number on iOS 7
  • Rest Services conventions
  • git add error : “fatal : malloc, out of memory”
  • Best way to dynamically load an xml configuration file into a Flex4/Flash movie at runtime?
  • 550 Access denied - Invalid HELO name
  • Android app gives error “BatteryStatsImpl: reading network stats”
  • Security issues with PHP's Readfile method
  • Web.config system.webserver errors
  • Problem deserializing objects from cache on MyBatis 3/Java
  • Converting a WriteableBitmap image ToArray in UWP
  • PHP buffered output depending on server setting?
  • Custom validator control occupying space even though display set to dynamic
  • ImageMagick, replace semi-transparent white with opaque white
  • Reading JSON from a file using C++ REST SDK (Casablanca)
  • Cannot connect to cassandra from Spark
  • Why is an OPTIONS request sent to the server?
  • FB SDK and cURL: Unknown SSL protocol error in connection to graph.facebook.com:443
  • Is there any way to access browser form field suggestions from JavaScript?
  • Resize panoramic image to fixed size
  • Volusion's generic SQL folder, functionality
  • Is there a mandatory requirement to switch app.yaml?
  • How do you join a server to an Active Directory (domain)?
  • coudnt use logback because of log4j
  • UserPrincipal.Current returns apppool on IIS