1CURLOPT_FOLLOWLOCATION(3) curl_easy_setopt options CURLOPT_FOLLOWLOCATION(3)
2
3
4
6 CURLOPT_FOLLOWLOCATION - follow HTTP 3xx redirects
7
9 #include <curl/curl.h>
10
11 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FOLLOWLOCATION, long
12 enable);
13
15 A long parameter set to 1 tells the library to follow any Location:
16 header that the server sends as part of an HTTP header in a 3xx
17 response. The Location: header can specify a relative or an absolute
18 URL to follow.
19
20 libcurl will issue another request for the new URL and follow new Loca‐
21 tion: headers all the way until no more such headers are returned.
22 CURLOPT_MAXREDIRS(3) can be used to limit the number of redirects
23 libcurl will follow.
24
25 libcurl limits what protocols it automatically follows to. The accepted
26 protocols are set with CURLOPT_REDIR_PROTOCOLS(3). By default libcurl
27 will allow all protocols on redirect except those disabled for security
28 reasons: Since 7.19.4 FILE and SCP are disabled, and since 7.40.0 SMB
29 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
33 request: For 301, 302 and 303 responses libcurl will switch method to
34 GET unless CURLOPT_POSTREDIR(3) instructs libcurl otherwise. All other
35 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 very easy to instead implement
39 your own 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
44 0, disabled
45
47 HTTP(S)
48
50 CURL *curl = curl_easy_init();
51 if(curl) {
52 curl_easy_setopt(curl, CURLOPT_URL, "http://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
61 Along with HTTP
62
64 Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
65
67 CURLOPT_REDIR_PROTOCOLS(3), CURLOPT_PROTOCOLS(3), CURLOPT_POSTREDIR(3),
68 CURLINFO_REDIRECT_URL(3), CURLINFO_REDIRECT_COUNT(3),
69
70
71
72libcurl 7.61.1 May 02, 2018 CURLOPT_FOLLOWLOCATION(3)