On this page
When an HTML form is submitted, its method determines where the browser puts the form data. A GET form usually puts it in the URL’s query string; a POST form puts it in the request body. This GET vs POST form URL distinction affects sharing, browser history, logging, and how you handle sensitive information.
Key Takeaways
- Use GET for searches and other read-only operations when the resulting URL should be bookmarkable or shareable.
- Use POST for operations that change server state and for data that should not appear in the query string.
- POST is not encryption. Use HTTPS and appropriate access controls, validation, and logging practices.
- Only successful form controls are submitted: for example, an input generally needs a
name, and unchecked checkboxes are omitted.
GET vs POST form URLs
Consider a page at https://example.com with forms that submit a field named q containing red shoes.
| Form method | Where the field is sent | Example destination |
|---|---|---|
| GET | In the URL query string | https://example.com/search?q=red+shoes |
| POST | In the HTTP request body | https://example.com/search |
The POST destination can still have a query string of its own; POST does not remove parameters already present in the action URL. The distinction is where the form’s submitted fields go.
For a normal HTML form, GET is the default if method is omitted. A POST form defaults to application/x-www-form-urlencoded encoding, unless its encoding is changed. Neither method determines what the server does with the data: the server must implement the corresponding route and behavior.
Advertisement
A shareable GET search form
Save this as an HTML page served from https://example.com, or adapt the action to a search endpoint on your own site:
<form action="/search" method="get">
<label for="search-query">Search</label>
<input id="search-query" name="q" type="search" required>
<button type="submit">Search</button>
</form>
If someone enters red shoes, the browser navigates to a URL like:
https://example.com/search?q=red+shoes
The browser encodes the space as + in this form query string. The server’s /search handler can read q and return matching results. A recipient can open the same URL to repeat the search, although results may differ because of permissions, personalization, or changing data.
GET is a good fit here because a search is normally read-only and the query is useful in a bookmark. Treat the URL as potentially shareable: anyone who receives it can see the search term. Do not use this pattern for searches containing information that must remain confidential.
For GET forms, the browser constructs the query from the submitted fields. Do not rely on parameters already in the action URL being retained; represent required parameters as named form controls instead.
A POST form and its request body
A login form is a common reason to keep submitted values out of the query string:
<form action="/login" method="post">
<label for="username">Username</label>
<input id="username" name="username" autocomplete="username" required>
<label for="password">Password</label>
<input id="password" name="password" type="password"
autocomplete="current-password" required>
<button type="submit">Sign in</button>
</form>
With the default form encoding, the request body has the shape below. The values shown are fictional, and the password is still readable in the body before transport encryption:
username=example-user&password=example-password
The browser sends that body to /login; it does not add these fields to the address bar as the form query string. The server must accept POST at that route and parse the form body. This snippet illustrates submission only; it is not a complete authentication implementation.
For file uploads, use POST with enctype="multipart/form-data" and a server-side multipart parser. An ordinary URL-encoded form is not a substitute for that upload setup.
Advertisement
Why query strings are risky for sensitive data
URLs can be retained or copied in browser history, bookmarks, server and proxy logs, analytics systems, and shared links. Depending on the page and referrer policy, a URL may also be included in a Referer header when navigating to another site. Avoid putting passwords, access tokens, or sensitive personal information in query strings.
Moving data into a POST body reduces those URL-specific exposures, but it does not make the data secret by itself. Bodies can also be inspected, logged, stored, or exposed by the client, server, or intermediaries. Use HTTPS for transport, restrict access to the data, and configure logs and application code not to record secrets unnecessarily. HTTPS does not prevent an endpoint or the browser from seeing data it handles.
POST endpoints that change state may also need cross-site request forgery defenses, such as appropriately validated CSRF tokens, alongside suitable cookie settings. A method choice alone is not an authorization check.
Try it in browser developer tools
- Serve a page containing one of the forms from a development server you control, with a matching endpoint that accepts the chosen method.
- Open the browser’s developer tools and select the Network panel. Submit fictional, non-sensitive values.
- Select the form submission request. For GET, inspect the request URL and query parameters. For POST, inspect the request method and form data or request payload.
- Check the address bar as well. If the server redirects after submission, inspect both the initial request and the redirect rather than assuming the final address describes the original request.
Developer tools can show POST bodies, so use dummy values when sharing screenshots or recordings. The examples in this article have not been executed as part of its preparation.
Common Mistakes
- Using GET for changes. Links, reloads, and automated clients may repeat GET requests. Use an appropriate state-changing method and enforce authorization on the server.
- Treating hidden fields as private. Hidden inputs are still submitted and can be viewed or modified by the user.
- Assuming POST hides everything. The action URL, including any existing query parameters, remains a URL; request bodies also need protection.
- Forgetting
name. An input without anamegenerally does not contribute a field to the submission. - Assuming every reload is harmless. Reloading after a POST can prompt a resubmission and may repeat an operation.
Best Practices
Choose GET for safe, read-only forms where a reusable URL is helpful. Choose POST for state changes and when fields should not be placed in the URL. Validate input and enforce permissions server-side for either method.
After a successful state-changing POST, consider redirecting to a GET result page. This Post/Redirect/Get pattern can reduce accidental resubmissions on refresh, but it does not replace server-side safeguards against duplicate operations.
Conclusion
GET makes form fields part of a reusable URL; POST normally places them in the request body. Pick the method based on the operation and sharing needs, then protect sensitive data independently of that choice.
The HTML Standard’s form submission rules and MDN’s HTML form documentation provide further detail. Those sources were not retrieved during preparation of this article, so readers should consult them directly for current browser behavior.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.