CURLOPT_POSTREDIR.md (2309B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_POSTREDIR 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLINFO_EFFECTIVE_METHOD (3) 9 - CURLINFO_REDIRECT_COUNT (3) 10 - CURLOPT_FOLLOWLOCATION (3) 11 - CURLOPT_MAXREDIRS (3) 12 - CURLOPT_POSTFIELDS (3) 13 Protocol: 14 - HTTP 15 Added-in: 7.19.1 16 --- 17 18 # NAME 19 20 CURLOPT_POSTREDIR - how to act on an HTTP POST redirect 21 22 # SYNOPSIS 23 24 ~~~c 25 #include <curl/curl.h> 26 27 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POSTREDIR, 28 long bitmask); 29 ~~~ 30 31 # DESCRIPTION 32 33 Pass a bitmask to control how libcurl acts on redirects after POSTs that get a 34 301, 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 36 6.4.2 to 6.4.4) and not convert POST requests into GET requests when following 37 a 301 redirection. Setting bit 1 (value **CURL_REDIR_POST_302**) makes 38 libcurl maintain the request method after a 302 redirect whilst setting bit 2 39 (value **CURL_REDIR_POST_303**) makes libcurl maintain the request method 40 after a 303 redirect. The value **CURL_REDIR_POST_ALL** is a convenience 41 define that sets all three bits. 42 43 The non-RFC behavior is ubiquitous in web browsers, so the library does the 44 conversion by default to maintain consistency. However, a server may require a 45 POST to remain a POST after such a redirection. This option is meaningful only 46 when setting CURLOPT_FOLLOWLOCATION(3). 47 48 # DEFAULT 49 50 0 51 52 # %PROTOCOLS% 53 54 # EXAMPLE 55 56 ~~~c 57 int 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, (long)CURL_REDIR_POST_ALL); 69 70 curl_easy_perform(curl); 71 } 72 } 73 ~~~ 74 75 # HISTORY 76 77 This option was known as CURLOPT_POST301 up to 7.19.0 as it only supported the 78 301 then. CURL_REDIR_POST_303 was added in 7.26.0. 79 80 # %AVAILABILITY% 81 82 # RETURN VALUE 83 84 curl_easy_setopt(3) returns a CURLcode indicating success or error. 85 86 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 87 libcurl-errors(3).