1CURLOPT_URL(3)             curl_easy_setopt options             CURLOPT_URL(3)
2
3
4

NAME

6       CURLOPT_URL - URL for this transfer
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLcode curl_easy_setopt(CURL *handle, CURLOPT_URL, char *URL);
12

DESCRIPTION

14       Pass  in  a  pointer to the URL to work with. The parameter should be a
15       char * to a null-terminated string which must  be  URL-encoded  in  the
16       following format:
17
18       scheme://host:port/path
19
20       For a greater explanation of the format please see RFC3986.
21
22       libcurl  does  not  validate  the syntax or use this variable until the
23       transfer is issued. Even if you set a crazy value  here,  curl_easy_se‐
24       topt(3) will still return CURLE_OK.
25
26       If  the  given  URL  is  missing  a  scheme  name (such as "http://" or
27       "ftp://" etc) then libcurl will make a guess based on the host. If  the
28       outermost  sub-domain  name matches DICT, FTP, IMAP, LDAP, POP3 or SMTP
29       then that protocol will be used, otherwise HTTP  will  be  used.  Since
30       7.45.0 guessing can be disabled by setting a default protocol, see CUR‐
31       LOPT_DEFAULT_PROTOCOL(3) for details.
32
33       Should the protocol, either that specified by the scheme or deduced  by
34       libcurl  from the host name, not be supported by libcurl then CURLE_UN‐
35       SUPPORTED_PROTOCOL will be  returned  from  either  the  curl_easy_per‐
36       form(3)  or  curl_multi_perform(3)  functions  when  you call them. Use
37       curl_version_info(3) for detailed information of  which  protocols  are
38       supported by the build of libcurl you are using.
39
40       CURLOPT_PROTOCOLS(3)  can  be used to limit what protocols libcurl will
41       use for this transfer, independent of what libcurl has been compiled to
42       support.  That  may  be  useful  if you accept the URL from an external
43       source and want to limit the accessibility.
44
45       The CURLOPT_URL(3) string will be ignored if CURLOPT_CURLU(3) is set.
46
47       CURLOPT_URL(3) or CURLOPT_CURLU(3) must be set  before  a  transfer  is
48       started.
49
50       The  application  does not have to keep the string around after setting
51       this option.
52

ENCODING

54       The string pointed to in the CURLOPT_URL(3) argument is  generally  ex‐
55       pected  to be a sequence of characters using an ASCII compatible encod‐
56       ing.
57
58       If libcurl is built with IDN support, the server name part of  the  URL
59       can  use an "international name" by using the current encoding (accord‐
60       ing to locale) or UTF-8 (when winidn is  used;  or  a  Windows  Unicode
61       build using libidn2).
62
63       If  libcurl  is  built without IDN support, the server name is used ex‐
64       actly as specified when passed to the name resolver functions.
65

DEFAULT

67       There is no default URL. If this option is not set, no transfer can  be
68       performed.
69

SECURITY CONCERNS

71       Applications  may at times find it convenient to allow users to specify
72       URLs for various purposes and that string would then end up fed to this
73       option.
74
75       Getting  a  URL from an external untrusted party will bring reasons for
76       several security concerns:
77
78       If you have an application that runs as or  in  a  server  application,
79       getting an unfiltered URL can easily trick your application to access a
80       local resource instead of a remote. Protecting yourself against  local‐
81       host accesses is hard when accepting user provided URLs.
82
83       Such  custom  URLs can also access other ports than you planned as port
84       numbers are part of the regular URL format. The combination of a  local
85       host  and  a custom port number can allow external users to play tricks
86       with your local services.
87
88       Accepting external URLs may also use other protocols  than  http://  or
89       other common ones. Restrict what accept with CURLOPT_PROTOCOLS(3).
90
91       User  provided  URLs  can  also be made to point to sites that redirect
92       further on (possibly  to  other  protocols  too).  Consider  your  CUR‐
93       LOPT_FOLLOWLOCATION(3) and CURLOPT_REDIR_PROTOCOLS(3) settings.
94

PROTOCOLS

96       All
97

EXAMPLE

99       CURL *curl = curl_easy_init();
100       if(curl) {
101         curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
102
103         curl_easy_perform(curl);
104       }
105

AVAILABILITY

107       POP3 and SMTP were added in 7.31.0
108

RETURN VALUE

110       Returns  CURLE_OK on success or CURLE_OUT_OF_MEMORY if there was insuf‐
111       ficient heap space.
112
113       Note that curl_easy_setopt(3) will not actually parse the given  string
114       so  given a bad URL, it will not be detected until curl_easy_perform(3)
115       or similar is called.
116

SEE ALSO

118       CURLOPT_VERBOSE(3), CURLOPT_PROTOCOLS(3), CURLOPT_FORBID_REUSE(3), CUR‐
119       LOPT_FRESH_CONNECT(3),  curl_easy_perform(3), CURLINFO_REDIRECT_URL(3),
120       CURLOPT_PATH_AS_IS(3), CURLOPT_CURLU(3),
121
122
123
124libcurl 7.85.0                   May 17, 2022                   CURLOPT_URL(3)
Impressum