CURLOPT_POSTREDIR.3 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. .\" generated by cd2nroff 0.1 from CURLOPT_POSTREDIR.md
  2. .TH CURLOPT_POSTREDIR 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_POSTREDIR \- how to act on an HTTP POST redirect
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POSTREDIR,
  9. long bitmask);
  10. .fi
  11. .SH DESCRIPTION
  12. Pass a bitmask to control how libcurl acts on redirects after POSTs that get a
  13. 301, 302 or 303 response back. A parameter with bit 0 set (value
  14. \fBCURL_REDIR_POST_301\fP) tells the library to respect RFC 7231 (section
  15. 6.4.2 to 6.4.4) and not convert POST requests into GET requests when following
  16. a 301 redirection. Setting bit 1 (value \fBCURL_REDIR_POST_302\fP) makes
  17. libcurl maintain the request method after a 302 redirect whilst setting bit 2
  18. (value \fBCURL_REDIR_POST_303\fP) makes libcurl maintain the request method
  19. after a 303 redirect. The value \fBCURL_REDIR_POST_ALL\fP is a convenience
  20. define that sets all three bits.
  21. The non\-RFC behavior is ubiquitous in web browsers, so the library does the
  22. conversion by default to maintain consistency. However, a server may require a
  23. POST to remain a POST after such a redirection. This option is meaningful only
  24. when setting \fICURLOPT_FOLLOWLOCATION(3)\fP.
  25. .SH DEFAULT
  26. 0
  27. .SH PROTOCOLS
  28. This functionality affects http only
  29. .SH EXAMPLE
  30. .nf
  31. int main(void)
  32. {
  33. CURL *curl = curl_easy_init();
  34. if(curl) {
  35. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  36. /* a silly POST example */
  37. curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "data=true");
  38. /* example.com is redirected, so we tell libcurl to send POST on 301,
  39. 302 and 303 HTTP response codes */
  40. curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
  41. curl_easy_perform(curl);
  42. }
  43. }
  44. .fi
  45. .SH HISTORY
  46. This option was known as CURLOPT_POST301 up to 7.19.0 as it only supported the
  47. 301 then. CURL_REDIR_POST_303 was added in 7.26.0.
  48. .SH AVAILABILITY
  49. Added in curl 7.19.1
  50. .SH RETURN VALUE
  51. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  52. .SH SEE ALSO
  53. .BR CURLINFO_EFFECTIVE_METHOD (3),
  54. .BR CURLINFO_REDIRECT_COUNT (3),
  55. .BR CURLOPT_FOLLOWLOCATION (3),
  56. .BR CURLOPT_MAXREDIRS (3),
  57. .BR CURLOPT_POSTFIELDS (3)