How to Keep Same HTTP Method After Curl Redirect

When using cURL to follow HTTP redirects, the tool’s default behavior often converts POST requests into GET requests. This article explains how to use the specific cURL options --post301, --post302, and --post303 to maintain the original HTTP POST method across redirects.

By default, when you use the -L or --location option to follow redirects, cURL adheres to historical browser behavior. If a server responds with a 301, 302, or 303 redirect status code in response to a POST request, cURL will automatically convert the subsequent request to a GET request.

To force cURL to maintain the POST method after a redirect, you must use specific command-line options depending on the HTTP status code returned by the server:

Example Usage

To send a POST request and ensure the POST method is maintained if the server redirects with either a 301 or 302 status code, you can combine the flags with the location option:

curl -L --post301 --post302 -d "param1=value1" https://example.com/api

For non-POST methods (such as PUT or DELETE), cURL preserves the HTTP method during redirects automatically. These specific options are only required to prevent POST from being converted to GET.