1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLINFO_REDIRECT_URL 5Section: 3 6Source: libcurl 7See-also: 8 - CURLINFO_REDIRECT_COUNT (3) 9 - CURLINFO_REDIRECT_TIME_T (3) 10 - CURLOPT_FOLLOWLOCATION (3) 11 - curl_easy_getinfo (3) 12 - curl_easy_setopt (3) 13Protocol: 14 - HTTP 15--- 16 17# NAME 18 19CURLINFO_REDIRECT_URL - get the URL a redirect would go to 20 21# SYNOPSIS 22 23~~~c 24#include <curl/curl.h> 25 26CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_REDIRECT_URL, char **urlp); 27~~~ 28 29# DESCRIPTION 30 31Pass a pointer to a char pointer to receive the URL a redirect *would* 32take you to if you would enable CURLOPT_FOLLOWLOCATION(3). This can come 33handy if you think using the built-in libcurl redirect logic is not good enough 34for you but you would still prefer to avoid implementing all the magic of 35figuring out the new URL. 36 37This URL is also set if the CURLOPT_MAXREDIRS(3) limit prevented a 38redirect to happen (since 7.54.1). 39 40# EXAMPLE 41 42~~~c 43int main(void) 44{ 45 CURL *curl = curl_easy_init(); 46 if(curl) { 47 CURLcode res; 48 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 49 res = curl_easy_perform(curl); 50 if(res == CURLE_OK) { 51 char *url = NULL; 52 curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &url); 53 if(url) 54 printf("Redirect to: %s\n", url); 55 } 56 curl_easy_cleanup(curl); 57 } 58} 59~~~ 60 61# AVAILABILITY 62 63Added in 7.18.2 64 65# RETURN VALUE 66 67Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. 68