iblue
iblue

Reputation: 30434

Does a 302 Redirect requires a GET request?

I am building an API for a web service and I have been asking myself. Imagine there as an API call to create a new project, like /api/project/create.json and it redirects (with a 302 Redirect) to the newly created project, say /api/project/123.json. If the first request is sent via POST, where is specifed, that the second URI must be retrived with GET?

Is there any RFC that states, that redirects always must be followed with GET? Or is it valid client behavior to just change the URL and send the same POST request again to the new URL?

Imagine I have and old API server and a new API server and I wanted to redirect the clients POST-Request to the new API-URL. What do I have to do?

Upvotes: 0

Views: 303

Answers (1)

Julian Reschke
Julian Reschke

Reputation: 42065

If the first request is sent via POST, where is specifed, that the second URI must be retrived with GET?

Nowhere.

Is there any RFC that states, that redirects always must be followed with GET? Or is it valid client behavior to just change the URL and send the same POST request again to the new URL?

No, actually the RFC (RFC 2616) states that changing the method name on 301 and 302 is incorrect.

See also http://greenbytes.de/tech/webdav/draft-ietf-httpbis-p2-semantics-19.html#status.3xx for more information.

Imagine I have and old API server and a new API server and I wanted to redirect the clients POST-Request to the new API-URL. What do I have to do?

I would recommend using status code 307 (because there are fewer browser bugs around that one).

Upvotes: 1

Related Questions