1---
2c: Copyright (C) Daniel Stenberg, <daniel.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)
11---
12
13# NAME
14
15CURLINFO_EFFECTIVE_URL - get the last used URL
16
17# SYNOPSIS
18
19~~~c
20#include <curl/curl.h>
21
22CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_EFFECTIVE_URL, char **urlp);
23~~~
24
25# DESCRIPTION
26
27Pass in a pointer to a char pointer and get the last used effective URL.
28
29In cases when you have asked libcurl to follow redirects, it may not be the same
30value you set with CURLOPT_URL(3).
31
32The **urlp** pointer is NULL or points to private memory. You MUST NOT free
33- it gets freed when you call curl_easy_cleanup(3) on the corresponding
34CURL handle.
35
36# PROTOCOLS
37
38HTTP(S)
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    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
50    res = curl_easy_perform(curl);
51    if(res == CURLE_OK) {
52      char *url = NULL;
53      curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
54      if(url)
55        printf("Redirect to: %s\n", url);
56    }
57    curl_easy_cleanup(curl);
58  }
59}
60~~~
61
62# AVAILABILITY
63
64Added in 7.4
65
66# RETURN VALUE
67
68Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
69