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