1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLINFO_EFFECTIVE_URL 5Section: 3 6Source: libcurl 7See-also: 8 - CURLOPT_FOLLOWLOCATION (3) 9 - curl_easy_getinfo (3) 10 - curl_easy_setopt (3) 11Protocol: 12 - HTTP 13Added-in: 7.4 14--- 15 16# NAME 17 18CURLINFO_EFFECTIVE_URL - get the last used URL 19 20# SYNOPSIS 21 22~~~c 23#include <curl/curl.h> 24 25CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_EFFECTIVE_URL, char **urlp); 26~~~ 27 28# DESCRIPTION 29 30Pass in a pointer to a char pointer and get the last used effective URL. 31 32In cases when you have asked libcurl to follow redirects, it may not be the same 33value you set with CURLOPT_URL(3). 34 35The **urlp** pointer is NULL or points to private memory. You MUST NOT free 36- it gets freed when you call curl_easy_cleanup(3) on the corresponding 37CURL handle. 38 39# %PROTOCOLS% 40 41# EXAMPLE 42 43~~~c 44int main(void) 45{ 46 CURL *curl = curl_easy_init(); 47 if(curl) { 48 CURLcode res; 49 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 50 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); 51 res = curl_easy_perform(curl); 52 if(res == CURLE_OK) { 53 char *url = NULL; 54 curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url); 55 if(url) 56 printf("Redirect to: %s\n", url); 57 } 58 curl_easy_cleanup(curl); 59 } 60} 61~~~ 62 63# %AVAILABILITY% 64 65# RETURN VALUE 66 67Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. 68