You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
curl --request POST --follow http://some/url/that/returns/303
Try adding the -v option. You'll see the following warning:
Note: Unnecessary use of -X or --request, POST is already inferred.
Then try again after removing --request. It is very seldom the right option to use.
True, that's the case for curl --request POST --data '' etc, but the same issue is present for the other HTTP verbs. I would think that if --data was required to make --follow work correctly it would at least be mentioned in the docs, but the example given in the man entry is
Example:
curl -X POST --follow https://example.com
Edit: Also, as far as I can tell the only reason for --followis to handle invocations with --request. E.g. curl --data '' --location http://returns/303 also switches to GET for the redirect.
What --data does is turn on the POST method in the correct way, enabling actual
POST behaviour in libcurl. Using -X does a "fake" POST that libcurl actually
treats as a GET internally. --data (or similar) changes that internal GET
behavior into the POST you're expecting. That's why -X is so insidious and
its use wrong 99.9% (thereabouts) of the time.
See https://daniel.haxx.se/blog/2015/09/11/unnecessary-use-of-curl-x/
Regarding documentation, it does say "Normally you do not need this option" as
well as "curl does not change request method according to the HTTP 30x
response codes" and even warns you not to use it at run with in verbose mode.
If --location is used, the method string you set with --request is used for all requests, which may cause unintended side-effects when curl does not change request method according to the HTTP 30x response codes - and similar. Consider using --follow instead in combination with --request.
As far as I know the only way to get e.g. DELETE with curl is by using --request. It isn’t obvious from the docs that you need to add --data to the DELETE (uncommon) to get --follow to work. It just says “use --follow with --request”.
There are rare but legitimate reasons to use -X like this and raising a big
nasty warning every time would mess up people's workflows. In between showing a
verbose warning, multiple places where it's documented and even blog posts,
there's only so much we should legitimately be doing to prevent people from
shooting themselves in the foot. curl is a powerful tool that is used in all
kinds of weird and wacky ways, by design.
This seems like a bug or an oversight to me. I tried builds from 13cbabf (curl: add --follow) and master, using --request and --follow, with 301, 302 and 303 responses and all of them kept the original --request method.
The method string set with --request is used in subsequent requests for the status codes 307 or 308, but may be reset to GET for 301, 302 and 303.
CURLFOLLOW_OBEYCODE says:
Note that only POST (or a custom post) is changed to GET on 301/302, its not change PUT etc - and therefore also not when libcurl issues a custom PUT. A 303 response makes it switch to GET independently of the original method (except for HEAD).
Setting the CURLFOLLOW_OBEYCODE bit makes libcurl not use the custom set method after redirects for 301, 302 and 303 responses. Unless the CURLOPT_POSTREDIR bits are set for those status codes.
IMO the situation is confusing.
The code in the http handler for 301/302/303 is very POST-specific, it's written in a way that it won't call http_switch_to_get for a just a custom request with obeycode:
I could modify it of course to "fix" the reporter's issue (click here for diff)
diff --git a/lib/http.c b/lib/http.c
index 9de27ba..16a1ae0 100644
--- a/lib/http.c+++ b/lib/http.c@@ -1321,10 +1321,12 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl,
* This behavior is forbidden by RFC1945 and the obsolete RFC2616, and
* can be overridden with CURLOPT_POSTREDIR.
*/
- if((data->state.httpreq == HTTPREQ_POST ||- data->state.httpreq == HTTPREQ_POST_FORM ||- data->state.httpreq == HTTPREQ_POST_MIME) &&- !data->set.post301) {+ if(((data->state.httpreq == HTTPREQ_POST ||+ data->state.httpreq == HTTPREQ_POST_FORM ||+ data->state.httpreq == HTTPREQ_POST_MIME) &&+ !data->set.post301) ||+ (data->set.str[STRING_CUSTOMREQUEST] &&+ data->set.http_follow_mode == CURLFOLLOW_OBEYCODE)) {
http_switch_to_get(data, 301);
switch_to_get = TRUE;
}
@@ -1346,10 +1348,12 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl,
* This behavior is forbidden by RFC1945 and the obsolete RFC2616, and
* can be overridden with CURLOPT_POSTREDIR.
*/
- if((data->state.httpreq == HTTPREQ_POST ||- data->state.httpreq == HTTPREQ_POST_FORM ||- data->state.httpreq == HTTPREQ_POST_MIME) &&- !data->set.post302) {+ if(((data->state.httpreq == HTTPREQ_POST ||+ data->state.httpreq == HTTPREQ_POST_FORM ||+ data->state.httpreq == HTTPREQ_POST_MIME) &&+ !data->set.post302) ||+ (data->set.str[STRING_CUSTOMREQUEST] &&+ data->set.http_follow_mode == CURLFOLLOW_OBEYCODE)) {
http_switch_to_get(data, 302);
switch_to_get = TRUE;
}
@@ -1361,11 +1365,13 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl,
* method is POST and the user specified to keep it as POST.
* https://github.com/curl/curl/issues/5237#issuecomment-614641049
*/
- if(data->state.httpreq != HTTPREQ_GET &&- ((data->state.httpreq != HTTPREQ_POST &&- data->state.httpreq != HTTPREQ_POST_FORM &&- data->state.httpreq != HTTPREQ_POST_MIME) ||- !data->set.post303)) {+ if((data->state.httpreq != HTTPREQ_GET &&+ ((data->state.httpreq != HTTPREQ_POST &&+ data->state.httpreq != HTTPREQ_POST_FORM &&+ data->state.httpreq != HTTPREQ_POST_MIME) ||+ !data->set.post303)) ||+ (data->set.str[STRING_CUSTOMREQUEST] &&+ data->set.http_follow_mode == CURLFOLLOW_OBEYCODE)) {
http_switch_to_get(data, 303);
switch_to_get = TRUE;
}
... but I think proposing a change like that is wrong and would break test1573, among others maybe, because it seems the intention was for OBEYCODE to only change custom requests back to GET in certain circumstances.
Activity
dfandrich commentedon Feb 25, 2026
thedanbob commentedon Feb 25, 2026
True, that's the case for
curl --request POST --data '' etc, but the same issue is present for the other HTTP verbs. I would think that if--datawas required to make--followwork correctly it would at least be mentioned in the docs, but the example given in the man entry isEdit: Also, as far as I can tell the only reason for
--followis to handle invocations with--request. E.g.curl --data '' --location http://returns/303also switches to GET for the redirect.docs: fix bad practice in --follow example
dfandrich commentedon Feb 25, 2026
dfandrich commentedon Feb 25, 2026
thedanbob commentedon Feb 25, 2026
That’s fair, but the documentation also says
As far as I know the only way to get e.g. DELETE with curl is by using
--request. It isn’t obvious from the docs that you need to add--datato the DELETE (uncommon) to get--followto work. It just says “use--followwith--request”.thedanbob commentedon Feb 25, 2026
I've edited the original issue to make it clear that it's a problem with all verbs, including the ones without dedicated command line flags.
vog commentedon Feb 26, 2026
I propose to raise the level of this warning, so it doesn't need
-vfor it to be shown. This may safe lots of users from serious headaches.benslimanh commentedon Feb 26, 2026
Agreed the man page example is misleading.
docs: fix bad practice in --follow example
dfandrich commentedon Feb 26, 2026
jay commentedon Mar 4, 2026
This seems like a bug or an oversight to me. I tried builds from 13cbabf (
curl: add --follow) and master, using --request and --follow, with 301, 302 and 303 responses and all of them kept the original --request method.jay commentedon Mar 4, 2026
Digging in a little deeper, --follow maps internally to CURLFOLLOW_OBEYCODE.
--follow says (emphasis mine):
CURLFOLLOW_OBEYCODE says:
... and then in the NOTE section it says:
IMO the situation is confusing.
The code in the http handler for 301/302/303 is very POST-specific, it's written in a way that it won't call
http_switch_to_getfor a just a custom request with obeycode:curl/lib/http.c
Lines 1396 to 1461 in 2eebc58
I could modify it of course to "fix" the reporter's issue (click here for diff)
... but I think proposing a change like that is wrong and would break test1573, among others maybe, because it seems the intention was for OBEYCODE to only change custom requests back to GET in certain circumstances.
curl/tests/data/test1573
Lines 68 to 88 in 2eebc58
IMO it makes more sense to always ignore custom request on 301/302/303 if follow is on but I guess it's a little late for that.http: always ignore custom method on 303 redirects
http: always ignore custom method on 303 redirects
http: on 303, switch to GET
http: on 303, switch to GET
http: on 303, switch to GET