CURLOPT_FOLLOWLOCATION.3 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. .\" generated by cd2nroff 0.1 from CURLOPT_FOLLOWLOCATION.md
  2. .TH CURLOPT_FOLLOWLOCATION 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_FOLLOWLOCATION \- follow HTTP 3xx redirects
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FOLLOWLOCATION, long enable);
  9. .fi
  10. .SH DESCRIPTION
  11. A long parameter set to 1 tells the library to follow any Location: header
  12. redirects that an HTTP server sends in a 30x response. The Location: header
  13. can specify a relative or an absolute URL to follow.
  14. libcurl issues another request for the new URL and follows subsequent new
  15. Location: redirects all the way until no more such headers are returned or the
  16. maximum limit is reached. \fICURLOPT_MAXREDIRS(3)\fP is used to limit the
  17. number of redirects libcurl follows.
  18. libcurl restricts what protocols it automatically follow redirects to. The
  19. accepted target protocols are set with \fICURLOPT_REDIR_PROTOCOLS_STR(3)\fP. By
  20. default libcurl allows HTTP, HTTPS, FTP and FTPS on redirects.
  21. When following a redirect, the specific 30x response code also dictates which
  22. request method libcurl uses in the subsequent request: For 301, 302 and 303
  23. responses libcurl switches method from POST to GET unless
  24. \fICURLOPT_POSTREDIR(3)\fP instructs libcurl otherwise. All other redirect
  25. response codes make libcurl use the same method again.
  26. For users who think the existing location following is too naive, too simple
  27. or just lacks features, it is easy to instead implement your own redirect
  28. follow logic with the use of \fIcurl_easy_getinfo(3)\fP\(aqs
  29. \fICURLINFO_REDIRECT_URL(3)\fP option instead of using
  30. \fICURLOPT_FOLLOWLOCATION(3)\fP.
  31. .SH NOTE
  32. Since libcurl changes method or not based on the specific HTTP response code,
  33. setting \fICURLOPT_CUSTOMREQUEST(3)\fP while following redirects may change
  34. what libcurl would otherwise do and if not that carefully may even make it
  35. misbehave since \fICURLOPT_CUSTOMREQUEST(3)\fP overrides the method libcurl
  36. would otherwise select internally.
  37. .SH DEFAULT
  38. 0, disabled
  39. .SH PROTOCOLS
  40. This functionality affects http only
  41. .SH EXAMPLE
  42. .nf
  43. int main(void)
  44. {
  45. CURL *curl = curl_easy_init();
  46. if(curl) {
  47. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  48. /* example.com is redirected, so we tell libcurl to follow redirection */
  49. curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  50. curl_easy_perform(curl);
  51. }
  52. }
  53. .fi
  54. .SH AVAILABILITY
  55. Added in curl 7.1
  56. .SH RETURN VALUE
  57. Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
  58. .SH SEE ALSO
  59. .BR CURLINFO_REDIRECT_COUNT (3),
  60. .BR CURLINFO_REDIRECT_URL (3),
  61. .BR CURLOPT_POSTREDIR (3),
  62. .BR CURLOPT_PROTOCOLS_STR (3),
  63. .BR CURLOPT_REDIR_PROTOCOLS_STR (3)