Search code examples
httpprotocolshttp-protocols

Does 302 redirect supports method forwarding?


We have a shortcut service in my company which basically provides redirection of short aliases to full URLs. The server runs a simple http redirection (302) service which uses the Host request header to a do a lookup with a file system based datastore.

I have a Resful Web Applciation and all the GET requests are working ok however POST/PUT requests are not reaching to server.

Does 302 "Redirect" by default keep the original requested method or it gets overwritten with GET types?


Solution

  • The 302 is generally implemented as specified by 303. To keep the original method, use 307 instead.

    See also 302 section of the HTTP status code definitions:

    Note: RFC 1945 and RFC 2068 specify that the client is not allowed to change the method on the redirected request. However, most existing user agent implementations treat 302 as if it were a 303 response, performing a GET on the Location field-value regardless of the original request method. The status codes 303 and 307 have been added for servers that wish to make unambiguously clear which kind of reaction is expected of the client.

    The 303 specifies that the new location should be requested by GET. The 307 keeps the original method.