Search code examples
asp.nethttphttp-redirectgetresponse

is response.redirect always an http GET response?


is response.redirect always an http GET response? or it could be POST?....


Solution

  • In most API's the standard redirect implementation does a 302 which is indeed per definition GET. As per your question history you're familiar with ASP.NET, I'll however add examples for Java Servlets as well.

    ASP.NET:

    Response.Redirect("http://google.com");
    

    Servlet:

    response.sendRedirect("http://google.com");
    

    It implicitly sets the response status to 302 and the Location header to the given URL.

    When the current request is a POST request and you want to redirect with POST, then you need a 307 redirect. This is not provided by the standard API, but it's usually just a matter of setting the appropriate response status and header.

    ASP.NET:

    Response.Status = "307 Temporary Redirect";
    Response.AddHeader("Location", "http://google.com");
    

    Servlet:

    response.setStatus(307);
    response.setHeader("Location", "http://google.com");
    

    Note that this will issue a security/confirmation warning on the average client which requests the enduser for confirmation to send the POST data to another location.