1CURLINFO_REDIRECT_URL(3) curl_easy_getinfo options CURLINFO_REDIRECT_URL(3)
2
3
4
6 CURLINFO_REDIRECT_URL - get the URL a redirect would go to
7
9 #include <curl/curl.h>
10
11 CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_REDIRECT_URL, char **urlp);
12
14 Pass a pointer to a char pointer to receive the URL a redirect would
15 take you to if you would enable CURLOPT_FOLLOWLOCATION(3). This can
16 come handy if you think using the built-in libcurl redirect logic is
17 not good enough for you but you would still prefer to avoid implement‐
18 ing all the magic of figuring out the new URL.
19
20 This URL is also set if the CURLOPT_MAXREDIRS(3) limit prevented a re‐
21 direct to happen (since 7.54.1).
22
24 HTTP(S)
25
27 CURL *curl = curl_easy_init();
28 if(curl) {
29 CURLcode res;
30 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
31 res = curl_easy_perform(curl);
32 if(res == CURLE_OK) {
33 char *url = NULL;
34 curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &url);
35 if(url)
36 printf("Redirect to: %s\n", url);
37 }
38 curl_easy_cleanup(curl);
39 }
40
42 Added in 7.18.2
43
45 Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION
46 if not.
47
49 curl_easy_getinfo(3), curl_easy_setopt(3),
50
51
52
53libcurl 7.82.0 November 26, 2021 CURLINFO_REDIRECT_URL(3)