CURLOPT_FOLLOWLOCATION.3 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" **************************************************************************
  22. .\"
  23. .TH CURLOPT_FOLLOWLOCATION 3 "17 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options"
  24. .SH NAME
  25. CURLOPT_FOLLOWLOCATION \- follow HTTP 3xx redirects
  26. .SH SYNOPSIS
  27. #include <curl/curl.h>
  28. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FOLLOWLOCATION, long enable);
  29. .SH DESCRIPTION
  30. A long parameter set to 1 tells the library to follow any Location: header
  31. that the server sends as part of an HTTP header in a 3xx response. The
  32. Location: header can specify a relative or an absolute URL to follow.
  33. libcurl will issue another request for the new URL and follow new Location:
  34. headers all the way until no more such headers are returned.
  35. \fICURLOPT_MAXREDIRS(3)\fP can be used to limit the number of redirects
  36. libcurl will follow.
  37. libcurl limits what protocols it automatically follows to. The accepted
  38. protocols are set with \fICURLOPT_REDIR_PROTOCOLS(3)\fP. By default libcurl
  39. will allow HTTP, HTTPS, FTP and FTPS on redirect (7.65.2). Older versions of
  40. libcurl allowed all protocols on redirect except those disabled for security
  41. reasons: Since 7.19.4 FILE and SCP are disabled, and since 7.40.0 SMB and SMBS
  42. are also disabled.
  43. When following a Location:, the 3xx response code that redirected it also
  44. dictates which request method it will use in the subsequent request: For 301,
  45. 302 and 303 responses libcurl will switch method from POST to GET unless
  46. \fICURLOPT_POSTREDIR(3)\fP instructs libcurl otherwise. All other 3xx codes
  47. will make libcurl send the same method again.
  48. For users who think the existing location following is too naive, too simple
  49. or just lacks features, it is very easy to instead implement your own redirect
  50. follow logic with the use of \fIcurl_easy_getinfo(3)\fP's
  51. \fICURLINFO_REDIRECT_URL(3)\fP option instead of using
  52. \fICURLOPT_FOLLOWLOCATION(3)\fP.
  53. .SH DEFAULT
  54. 0, disabled
  55. .SH PROTOCOLS
  56. HTTP(S)
  57. .SH EXAMPLE
  58. .nf
  59. CURL *curl = curl_easy_init();
  60. if(curl) {
  61. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  62. /* example.com is redirected, so we tell libcurl to follow redirection */
  63. curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  64. curl_easy_perform(curl);
  65. }
  66. .fi
  67. .SH AVAILABILITY
  68. Along with HTTP
  69. .SH RETURN VALUE
  70. Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
  71. .SH "SEE ALSO"
  72. .BR CURLOPT_REDIR_PROTOCOLS "(3), " CURLOPT_PROTOCOLS "(3), "
  73. .BR CURLOPT_POSTREDIR "(3), "
  74. .BR CURLINFO_REDIRECT_URL "(3), " CURLINFO_REDIRECT_COUNT "(3), "