301 Moved Permanently: Form POST Measured in 7 HTTP Clients
What happens after a form submission?
After a 301, of 7 measured clients: 7 arrived there as a GET without a body.
Reading the observations
Read the scope before the client entries.
Measured on Linux (x86_64, kernel 7.0.0-34-generic) against a local test server, with curl 8.18.0, GNU Wget 1.25.0, Python urllib.request 3.12.13, Python Requests 2.34.2, Python HTTPX 0.28.1, Node.js fetch 20.20.2, Chromium (HTML form) 149.0.7827.55. Windows, macOS, Firefox, Safari, older versions and other settings were not measured.
- curl 8.18.0: after a 301, the request arrived at the new address as a GET without its body.
- GNU Wget 1.25.0: after a 301, the request arrived at the new address as a GET without its body.
- Python urllib.request 3.12.13: after a 301, the request arrived at the new address as a GET without its body.
- Python Requests 2.34.2: after a 301, the request arrived at the new address as a GET without its body.
- Python HTTPX 0.28.1: after a 301, the request arrived at the new address as a GET without its body.
- Node.js fetch 20.20.2: after a 301, the request arrived at the new address as a GET without its body.
- Chromium (HTML form) 149.0.7827.55: after a 301, the request arrived at the new address as a GET without its body.
Documents and comparisons
Consider the excerpts alongside the measured totals.
“The 307 (Temporary Redirect) status code indicates that the target resource resides temporarily under a different URI and the user agent MUST NOT change the request method if it performs an automatic redirection to that URI.” — RFC 9110 §15.4.8
“Note: This status code is much younger (June 2014) than its sibling codes and thus might not be recognized everywhere.” — RFC 9110 §15.4.9
- After a 302, of 7 measured clients: 7 arrived there as a GET without a body.
- After a 303, of 7 measured clients: 7 arrived there as a GET without a body.
- After a 307, of 7 measured clients: 6 arrived there as a POST with its body; 1 did not go to the new address.
- After a 308, of 7 measured clients: 6 arrived there as a POST with its body; 1 did not go to the new address.
Choosing a response
If you control what the server answers with, weigh what the submission itself needs at the new address.
If the form data has to reach the new address, answer with 307 or 308: in this measurement, whenever a client went on to the new address after a 307 or 308, a POST with its body arrived there; after a 301, 302 or 303, a GET without a body arrived.
If your code posts with Python's urllib.request, handle 307 and 308 yourself: in this measurement it raised an error instead of going to the new address.
Match the redirect your server answers with to the journey your form is meant to take.
Does a 301 redirect change POST to GET?
“Note: For historical reasons, a user agent MAY change the request method from POST to GET for the subsequent request. If this behavior is undesired, the 308 (Permanent Redirect) status code can be used instead.” — RFC 9110 §15.4.2