1CURLOPT_FOLLOWLOCATION(3)  curl_easy_setopt options  CURLOPT_FOLLOWLOCATION(3)
2
3
4

NAME

6       CURLOPT_FOLLOWLOCATION - follow HTTP 3xx redirects
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FOLLOWLOCATION, long enable);
12

DESCRIPTION

14       A  long  parameter  set  to 1 tells the library to follow any Location:
15       header that the server sends as part of an HTTP header  in  a  3xx  re‐
16       sponse.  The Location: header can specify a relative or an absolute URL
17       to follow.
18
19       libcurl will issue another request for the new URL and follow new Loca‐
20       tion:  headers  all  the  way  until no more such headers are returned.
21       CURLOPT_MAXREDIRS(3) can be used  to  limit  the  number  of  redirects
22       libcurl will follow.
23
24       libcurl limits what protocols it automatically follows to. The accepted
25       protocols are set with CURLOPT_REDIR_PROTOCOLS(3). By  default  libcurl
26       will  allow  HTTP, HTTPS, FTP and FTPS on redirect (7.65.2). Older ver‐
27       sions of libcurl allowed all protocols on redirect  except  those  dis‐
28       abled for security reasons: Since 7.19.4 FILE and SCP are disabled, and
29       since 7.40.0 SMB and SMBS are also disabled.
30
31       When following a Location:, the 3xx response code  that  redirected  it
32       also  dictates  which  request method it will use in the subsequent re‐
33       quest: For 301, 302 and 303 responses libcurl will switch  method  from
34       POST  to  GET  unless CURLOPT_POSTREDIR(3) instructs libcurl otherwise.
35       All other 3xx codes will make libcurl send the same method again.
36
37       For users who think the existing location following is too  naive,  too
38       simple or just lacks features, it is easy to instead implement your own
39       redirect  follow  logic  with   the   use   of   curl_easy_getinfo(3)'s
40       CURLINFO_REDIRECT_URL(3)  option  instead  of using CURLOPT_FOLLOWLOCA‐
41       TION(3).
42

DEFAULT

44       0, disabled
45

PROTOCOLS

47       HTTP(S)
48

EXAMPLE

50       CURL *curl = curl_easy_init();
51       if(curl) {
52         curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
53
54         /* example.com is redirected, so we tell libcurl to follow redirection */
55         curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
56
57         curl_easy_perform(curl);
58       }
59

AVAILABILITY

61       Along with HTTP
62

RETURN VALUE

64       Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
65

SEE ALSO

67       CURLOPT_REDIR_PROTOCOLS(3), CURLOPT_PROTOCOLS(3), CURLOPT_POSTREDIR(3),
68       CURLINFO_REDIRECT_URL(3), CURLINFO_REDIRECT_COUNT(3),
69
70
71
72libcurl 8.0.1                  January 02, 2023      CURLOPT_FOLLOWLOCATION(3)
Impressum