Do 307 and 308 Redirects Preserve POST Requests?

Compare 307 vs 308 redirect POST behavior with 301 and 302, and run a safe local test for method and request-body preservation.

Published
Reading time
6 min read
Do 307 and 308 Redirects Preserve POST Requests?
On this page

A 307 or 308 redirect tells a client to repeat a request at another URL without changing its method. For a POST, that normally means sending the request body again. The distinction is whether the redirect is temporary or permanent—and whether the client can actually replay the body.

This comparison covers HTTP semantics, common client behavior, and a local test you can run without sending credentials or payment data.

Key Takeaways

  • 307 Temporary Redirect preserves the method when followed and indicates a temporary move.
  • 308 Permanent Redirect preserves the method when followed and indicates a permanent move.
  • 301 and 302 may cause a client to change POST to GET; they are not reliable choices when a POST must remain a POST.
  • A redirect is a second request. Client settings, body replayability, intermediaries, and application code can affect what reaches the destination.
  • Test with the actual clients and infrastructure you support, especially before making a redirect permanent.

307 vs 308 Redirect POST Behavior

StatusIntended durationPOST behavior when followed
301 Moved PermanentlyPermanentA client may change POST to GET.
302 FoundTemporaryA client may change POST to GET.
307 Temporary RedirectTemporaryThe client must not change the method.
308 Permanent RedirectPermanentThe client must not change the method.

HTTP specifies that a client following a 307 or 308 must not change the request method. A conforming client that follows a POST redirect will therefore make another POST, normally replaying the original request content. This does not guarantee that every client can resend a body: a streaming or otherwise non-replayable body may cause the client to fail rather than follow the redirect.

For historical compatibility, HTTP permits clients to change POST to GET after a 301 or 302. When that happens, clients typically omit the original POST body. Some clients preserve POST instead, depending on their configuration; do not rely on uniform behavior across libraries.

A 303 See Other is different: it directs the client to retrieve another resource, typically with GET. It can be appropriate after processing a form when the next request should display a result rather than repeat the submission.

Advertisement

Choose Temporary or Permanent Semantics

Use 307 when the original URL should remain the client's normal target, such as during a temporary migration. Use 308 when the target URL is intended to replace the original permanently. Both preserve the method when followed.

Permanent redirects can be cached or remembered by clients and intermediaries. Set an appropriate Cache-Control policy and test the change before deploying it broadly; changing a permanent redirect later may not immediately affect clients that retained it. Temporary does not mean invisible to caches under every configuration, so review your cache settings for either status.

The server emits a redirect response with a Location header; the client then decides whether and how to follow it. Redirects do not forward the original connection or guarantee identical headers. Authentication headers, cookies, and other metadata may be handled differently, particularly across origins. Avoid redirecting requests containing sensitive data to a different origin unless that flow has been deliberately designed and reviewed.

A redirect also does not guarantee exactly-once processing. If the original endpoint performs a side effect before returning the redirect, the destination may perform another. Design the flow so the redirecting endpoint does not process the submission, or use application-level idempotency controls where appropriate.

Test Redirects on a Local Endpoint

The following lab uses Python's standard library and curl. It binds only to 127.0.0.1, accepts a small form body, and returns the method and body observed at the destination. It is a diagnostic example, not a production HTTP server.

The example was not executed here, and current client documentation was not retrieved. Verify results with the versions used in your environment.

Save this as redirect_lab.py:

from http.server import BaseHTTPRequestHandler, HTTPServer


class Handler(BaseHTTPRequestHandler):
    def send_text(self, status, text, location=None):
        body = text.encode("utf-8")
        self.send_response(status)
        self.send_header("Content-Type", "text/plain; charset=utf-8")
        self.send_header("Content-Length", str(len(body)))
        self.send_header("Cache-Control", "no-store")
        if location is not None:
            self.send_header("Location", location)
        self.end_headers()
        self.wfile.write(body)

    def do_POST(self):
        try:
            length = int(self.headers.get("Content-Length", "0"))
        except ValueError:
            self.send_error(400, "Invalid Content-Length")
            return

        if length < 0 or length > 4096:
            self.send_error(413, "Body too large")
            return

        body = self.rfile.read(length).decode("utf-8", errors="replace")
        redirects = {
            "/redirect/301": 301,
            "/redirect/302": 302,
            "/redirect/307": 307,
            "/redirect/308": 308,
        }
        if self.path in redirects:
            self.send_text(redirects[self.path], "", "/receive")
        elif self.path == "/receive":
            self.send_text(200, f"method=POST\nbody={body}\n")
        else:
            self.send_error(404)

    def do_GET(self):
        if self.path == "/receive":
            self.send_text(200, "method=GET\nbody=\n")
        else:
            self.send_error(404)


if __name__ == "__main__":
    server = HTTPServer(("127.0.0.1", 8000), Handler)
    print("Listening on http://127.0.0.1:8000", flush=True)
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        pass
    finally:
        server.server_close()

Start the server:

python3 redirect_lab.py

In another terminal, send a fictional form value. -L tells curl to follow the redirect, and --data makes the initial request a POST:

curl -sS -L --data 'example=hello' http://127.0.0.1:8000/redirect/307

The expected final response is:

method=POST
body=example=hello

Repeat with /redirect/308; expect the same method and body. Then try /redirect/301 and /redirect/302. With curl's usual redirect behavior, those requests change to GET and the destination reports an empty body. Client options and versions can affect the result.

To inspect the redirect itself, omit -L and add -i:

curl -sS -i --data 'example=hello' http://127.0.0.1:8000/redirect/307

Look for the 307 status and Location: /receive header. Stop the server with Ctrl+C. The lab handles the small, content-length-delimited requests shown above; it is not intended to test arbitrary streaming uploads.

Advertisement

What to Check in Your Application

  1. Client configuration: Confirm that automatic redirect following is enabled, that the redirect limit is sufficient, and that the library can replay the request body. An upload stream may need to be recreated or buffered.
  2. Destination behavior: Log or inspect the received method and a harmless test body at the destination. Avoid logging real credentials, tokens, or payment data.
  3. Intermediaries: Check whether a proxy, gateway, or cache changes the status or Location, serves a cached redirect, or routes the destination differently.
  4. Application flow: Confirm that the original endpoint does not perform the action before redirecting, and decide how retries and duplicate submissions are handled.
  5. Origin and authentication: Check which headers and cookies the actual client sends to the destination. Do not assume authorization survives a cross-origin redirect.

For production verification, repeat the lab's comparison in a controlled staging environment using each supported HTTP library and representative body types. Record the client versions and settings alongside the observed results.

Common Mistakes

  • Using 301 or 302 when preserving POST is required. Some clients will switch to GET.
  • Assuming preservation means guaranteed delivery. A client may not follow redirects or may be unable to replay a body.
  • Forcing a method during testing without understanding the client option. For example, curl's -X POST changes the test and can mask its normal redirect-method behavior.
  • Treating a redirect as a transparent proxy. It creates a new request, potentially with different headers, credentials, routing, or cache behavior.
  • Testing with real secrets. Use fictional values and local or authorized staging endpoints.

Conclusion

Choose 307 for a temporary move and 308 for a permanent move when a followed POST must remain a POST. Neither status guarantees that a client can replay the body or that the destination will receive the same authentication context, so verify the complete flow with your clients and infrastructure.

What would your domain sell for?

A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.