xref: /curl/docs/libcurl/opts/CURLOPT_POSTREDIR.md (revision 5a488251)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_POSTREDIR
5Section: 3
6Source: libcurl
7See-also:
8  - CURLINFO_EFFECTIVE_METHOD (3)
9  - CURLINFO_REDIRECT_COUNT (3)
10  - CURLOPT_FOLLOWLOCATION (3)
11  - CURLOPT_MAXREDIRS (3)
12  - CURLOPT_POSTFIELDS (3)
13Protocol:
14  - HTTP
15Added-in: 7.19.1
16---
17
18# NAME
19
20CURLOPT_POSTREDIR - how to act on an HTTP POST redirect
21
22# SYNOPSIS
23
24~~~c
25#include <curl/curl.h>
26
27CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POSTREDIR,
28                          long bitmask);
29~~~
30
31# DESCRIPTION
32
33Pass a bitmask to control how libcurl acts on redirects after POSTs that get a
34301, 302 or 303 response back. A parameter with bit 0 set (value
35**CURL_REDIR_POST_301**) tells the library to respect RFC 7231 (section
366.4.2 to 6.4.4) and not convert POST requests into GET requests when following
37a 301 redirection. Setting bit 1 (value **CURL_REDIR_POST_302**) makes
38libcurl maintain the request method after a 302 redirect whilst setting bit 2
39(value **CURL_REDIR_POST_303**) makes libcurl maintain the request method
40after a 303 redirect. The value **CURL_REDIR_POST_ALL** is a convenience
41define that sets all three bits.
42
43The non-RFC behavior is ubiquitous in web browsers, so the library does the
44conversion by default to maintain consistency. However, a server may require a
45POST to remain a POST after such a redirection. This option is meaningful only
46when setting CURLOPT_FOLLOWLOCATION(3).
47
48# DEFAULT
49
500
51
52# %PROTOCOLS%
53
54# EXAMPLE
55
56~~~c
57int main(void)
58{
59  CURL *curl = curl_easy_init();
60  if(curl) {
61    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
62
63    /* a silly POST example */
64    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "data=true");
65
66    /* example.com is redirected, so we tell libcurl to send POST on 301,
67       302 and 303 HTTP response codes */
68    curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
69
70    curl_easy_perform(curl);
71  }
72}
73~~~
74
75# HISTORY
76
77This option was known as CURLOPT_POST301 up to 7.19.0 as it only supported the
78301 then. CURL_REDIR_POST_303 was added in 7.26.0.
79
80# %AVAILABILITY%
81
82# RETURN VALUE
83
84Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
85