Coding

GET vs POST: Differences, Safety, Caching and When to Use Each

Use GET to retrieve data: parameters go in the URL, the request changes nothing on the server, and the response can be cached and bookmarked. Use POST to send data for the server to process, such as a form submission, an upload or a new record: the data goes in the request body, and repeating the request may repeat the action.

GET vs POST at a glance

GETPOST
Purpose (RFC 9110)Transfer a current representation of the target resourceHave the target resource process the enclosed data
Where the data goesThe URL query string: /search?q=red+shoesThe request body
Request bodyNo defined meaning; avoid itYes
Safe (read-only)YesNo
IdempotentYesNo
CacheableYes, by defaultOnly with explicit freshness information and a matching Content-Location
Bookmarkable, shareableYesNo
Appears in browser history and server logsYes, including the parametersThe URL does; the body doesn't
Safe to retry automaticallyYesNot unless the client knows it is safe
Allowed in HTML formsYesYes

What the requests actually look like

We sent requests with curl to a small Python test server on our own machine that echoes back what it received. A GET with parameters:

curl "http://127.0.0.1:8765/search?q=red+shoes&page=2"
method=GET path=/search?q=red+shoes&page=2 content-type=None body=''

Everything is in the path. There is no body and no Content-Type. A POST of a form:

curl -d "[email protected]&plan=pro" http://127.0.0.1:8765/signup
method=POST path=/signup content-type=application/x-www-form-urlencoded body='[email protected]&plan=pro'

curl -d switched the method to POST and set the form content type on its own. A POST of JSON, the usual shape for APIs:

curl -H "Content-Type: application/json" -d '{"plan":"pro"}' http://127.0.0.1:8765/signup
method=POST path=/signup content-type=application/json body='{"plan":"pro"}'

And this is what the server's access log recorded for the first two requests, in Python http.server's default format:

127.0.0.1 - - [26/Oct/2026 19:52:51] "GET /search?q=red+shoes&page=2 HTTP/1.1" 200 -
127.0.0.1 - - [26/Oct/2026 19:52:51] "POST /signup HTTP/1.1" 200 -

The GET parameters are in the log. The email address sent by POST isn't. That difference is the practical heart of the "is POST more secure?" question, covered below. For more JSON examples, see curl POST JSON examples and fetch POST JSON in JavaScript.

Safe and idempotent: what they mean

RFC 9110, the current HTTP semantics standard, defines both terms, and they are the real reason the two methods behave differently.

Safe means the method is essentially read-only: the client doesn't request or expect any state change on the server. GET, HEAD, OPTIONS and TRACE are safe. The RFC says the purpose is to let crawlers and pre-fetching work "without fear of causing harm". That has a direct consequence for your code. The RFC's own example is a link like page?do=delete: if a GET URL performs a delete, a search engine crawler, a link checker or a browser's pre-fetch can trigger it just by following links. The RFC says the resource owner must disable such an action when it's accessed with a safe method.

Idempotent means sending the same request several times has the same intended effect as sending it once. PUT, DELETE and all safe methods are idempotent; POST is not. This is why a client can retry a failed GET automatically, while RFC 9110 says a client should not automatically retry a POST unless it has some way to know that's safe, and a proxy must not retry it. A repeated POST might place a second order.

Both properties describe what the client asked for, not everything the server does. A server logging every GET is still serving a safe request.

Caching

RFC 9110 says the response to a GET is cacheable unless headers say otherwise. POST responses are cacheable only when they include explicit freshness information and a Content-Location header matching the POST's target URI, and the RFC notes that most cache implementations only support caching GET and HEAD anyway. In practice: if you want browsers, CDNs and proxies to cache a response, it has to come from a GET.

Is POST more secure than GET?

Partly, and not in the way people often assume.

  • Not encrypted. A POST body travels as plain text over HTTP, just like the URL. Only HTTPS encrypts either, and it protects the path and query string in transit as well as the body.
  • Less exposure at rest. URLs end up in browser history, bookmarks, server and proxy access logs, and the Referer header sent to other sites. RFC 9110's security section says URIs "are intended to be shared, not secured" and that it is unwise to put sensitive or personally identifiable information in them. That is the real reason passwords, tokens and personal data belong in a POST body or a header, never in a query string.
  • No protection against forged requests. A malicious page can submit a POST form to your site as easily as it can load a GET URL. Protect state-changing requests with CSRF defences; see CSRF explained.

Can GET have a body?

You can send one. Our test server accepted it:

curl -X GET -d "q=red" http://127.0.0.1:8765/search
method=GET path=/search content-type=application/x-www-form-urlencoded body='q=red'

But RFC 9110 is clear that content in a GET request "has no generally defined semantics, cannot alter the meaning or target of the request", and might lead some implementations to reject the request and close the connection, because it can be used for request smuggling attacks. Clients should not send it unless the server has said it supports it. If a query is too complex for a URL, use POST.

URL length limits

HTTP itself sets no maximum. RFC 9110 recommends that all senders and recipients support URIs of at least 8,000 octets. Browsers, servers, CDNs and proxies each set their own limits beyond that, and a server that refuses a long URL returns 414 (URI Too Long). The RFC calls this a rare condition, likely when, for example, a client has improperly converted a POST into a GET with long query information. See HTTP status codes explained. If a request can carry a large or unpredictable amount of data, such as a list of thousands of IDs or a file, it belongs in a POST body.

Which to use: quick decision rules

  • Reading data, searching, filtering, paging: GET. Results are linkable and cacheable.
  • Creating something, submitting a form, uploading a file, triggering an action: POST. On success, the RFC says a server that created a resource should respond with 201 (Created) and a Location header.
  • Anything with passwords, tokens or personal data: POST body or a header, over HTTPS.
  • Replacing or deleting a known resource in an API: PUT or DELETE, which are idempotent and therefore safe to retry.
  • A GET that changes data: never. Crawlers and pre-fetchers will eventually call it.

For HTML forms, the method is set with <form method="get"> or method="post". The encoding of a POST form's body is set with the form's enctype attribute. MDN lists application/x-www-form-urlencoded (key=value pairs joined with &), multipart/form-data (needed for binary data such as file uploads) and text/plain.

Frequently asked questions

Is POST more secure than GET?
Only in one narrow way: POST data isn't in the URL, so it doesn't end up in browser history, bookmarks or server access logs. It is not encrypted by POST itself; anyone who can read the traffic can read a POST body just as easily as a URL. Use HTTPS for both.
Can a GET request have a body?
Technically a client can send one, but RFC 9110 says content in a GET request has no generally defined semantics, cannot change the meaning of the request, and may cause some implementations to reject the request. Put GET parameters in the query string instead.
What is the maximum length of a GET URL?
HTTP sets no fixed maximum. RFC 9110 recommends that senders and recipients support URIs of at least 8,000 octets. Real limits are set by browsers, servers and proxies, and a server that refuses a long URL responds with 414 URI Too Long. If parameters might grow large, use POST.
Should a search form use GET or POST?
GET, in most cases. A search doesn't change anything on the server, and GET makes the results page bookmarkable, shareable and cacheable. Use POST only if the search terms are sensitive enough that they shouldn't appear in URLs and logs.

Sources