1*6236dae4SAndroid Build Coastguard Worker--- 2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al. 3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl 4*6236dae4SAndroid Build Coastguard WorkerTitle: CURLOPT_URL 5*6236dae4SAndroid Build Coastguard WorkerSection: 3 6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl 7*6236dae4SAndroid Build Coastguard WorkerSee-also: 8*6236dae4SAndroid Build Coastguard Worker - CURLINFO_REDIRECT_URL (3) 9*6236dae4SAndroid Build Coastguard Worker - CURLOPT_CURLU (3) 10*6236dae4SAndroid Build Coastguard Worker - CURLOPT_FORBID_REUSE (3) 11*6236dae4SAndroid Build Coastguard Worker - CURLOPT_FRESH_CONNECT (3) 12*6236dae4SAndroid Build Coastguard Worker - CURLOPT_PATH_AS_IS (3) 13*6236dae4SAndroid Build Coastguard Worker - CURLOPT_PROTOCOLS_STR (3) 14*6236dae4SAndroid Build Coastguard Worker - curl_easy_perform (3) 15*6236dae4SAndroid Build Coastguard Worker - curl_url_get (3) 16*6236dae4SAndroid Build Coastguard Worker - curl_url_set (3) 17*6236dae4SAndroid Build Coastguard WorkerProtocol: 18*6236dae4SAndroid Build Coastguard Worker - All 19*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.1 20*6236dae4SAndroid Build Coastguard Worker--- 21*6236dae4SAndroid Build Coastguard Worker 22*6236dae4SAndroid Build Coastguard Worker# NAME 23*6236dae4SAndroid Build Coastguard Worker 24*6236dae4SAndroid Build Coastguard WorkerCURLOPT_URL - URL for this transfer 25*6236dae4SAndroid Build Coastguard Worker 26*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS 27*6236dae4SAndroid Build Coastguard Worker 28*6236dae4SAndroid Build Coastguard Worker~~~c 29*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h> 30*6236dae4SAndroid Build Coastguard Worker 31*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_URL, char *URL); 32*6236dae4SAndroid Build Coastguard Worker~~~ 33*6236dae4SAndroid Build Coastguard Worker 34*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION 35*6236dae4SAndroid Build Coastguard Worker 36*6236dae4SAndroid Build Coastguard WorkerPass in a pointer to the *URL* to work with. The parameter should be a 37*6236dae4SAndroid Build Coastguard Workerchar * to a null-terminated string which must be URL-encoded in the following 38*6236dae4SAndroid Build Coastguard Workerformat: 39*6236dae4SAndroid Build Coastguard Worker 40*6236dae4SAndroid Build Coastguard Workerscheme://host:port/path 41*6236dae4SAndroid Build Coastguard Worker 42*6236dae4SAndroid Build Coastguard WorkerFor a greater explanation of the format please see RFC 3986. 43*6236dae4SAndroid Build Coastguard Worker 44*6236dae4SAndroid Build Coastguard Workerlibcurl does not validate the syntax or use the URL until the transfer is 45*6236dae4SAndroid Build Coastguard Workerstarted. Even if you set a crazy value here, curl_easy_setopt(3) might 46*6236dae4SAndroid Build Coastguard Workerstill return *CURLE_OK*. 47*6236dae4SAndroid Build Coastguard Worker 48*6236dae4SAndroid Build Coastguard WorkerIf the given URL is missing a scheme name (such as "http://" or "ftp://" etc) 49*6236dae4SAndroid Build Coastguard Workerthen libcurl guesses based on the host. If the outermost subdomain name 50*6236dae4SAndroid Build Coastguard Workermatches DICT, FTP, IMAP, LDAP, POP3 or SMTP then that protocol gets used, 51*6236dae4SAndroid Build Coastguard Workerotherwise HTTP is used. Since 7.45.0 guessing can be disabled by setting a 52*6236dae4SAndroid Build Coastguard Workerdefault protocol, see CURLOPT_DEFAULT_PROTOCOL(3) for details. 53*6236dae4SAndroid Build Coastguard Worker 54*6236dae4SAndroid Build Coastguard WorkerShould the protocol, either as specified by the URL scheme or deduced by 55*6236dae4SAndroid Build Coastguard Workerlibcurl from the hostname, not be supported by libcurl then 56*6236dae4SAndroid Build Coastguard Worker*CURLE_UNSUPPORTED_PROTOCOL* is returned from either the curl_easy_perform(3) 57*6236dae4SAndroid Build Coastguard Workeror curl_multi_perform(3) functions when you call them. Use 58*6236dae4SAndroid Build Coastguard Workercurl_version_info(3) for detailed information of which protocols are supported 59*6236dae4SAndroid Build Coastguard Workerby the build of libcurl you are using. 60*6236dae4SAndroid Build Coastguard Worker 61*6236dae4SAndroid Build Coastguard WorkerCURLOPT_PROTOCOLS_STR(3) can be used to limit what protocols libcurl may 62*6236dae4SAndroid Build Coastguard Workeruse for this transfer, independent of what libcurl has been compiled to 63*6236dae4SAndroid Build Coastguard Workersupport. That may be useful if you accept the URL from an external source and 64*6236dae4SAndroid Build Coastguard Workerwant to limit the accessibility. 65*6236dae4SAndroid Build Coastguard Worker 66*6236dae4SAndroid Build Coastguard WorkerThe CURLOPT_URL(3) string is ignored if CURLOPT_CURLU(3) is set. 67*6236dae4SAndroid Build Coastguard Worker 68*6236dae4SAndroid Build Coastguard WorkerEither CURLOPT_URL(3) or CURLOPT_CURLU(3) must be set before a 69*6236dae4SAndroid Build Coastguard Workertransfer is started. 70*6236dae4SAndroid Build Coastguard Worker 71*6236dae4SAndroid Build Coastguard WorkerThe application does not have to keep the string around after setting this 72*6236dae4SAndroid Build Coastguard Workeroption. 73*6236dae4SAndroid Build Coastguard Worker 74*6236dae4SAndroid Build Coastguard WorkerUsing this option multiple times makes the last set string override the 75*6236dae4SAndroid Build Coastguard Workerprevious ones. Set it to NULL to disable its use again. Note however that 76*6236dae4SAndroid Build Coastguard Workerlibcurl needs a URL set to be able to performed a transfer. 77*6236dae4SAndroid Build Coastguard Worker 78*6236dae4SAndroid Build Coastguard WorkerThe parser used for handling the URL set with CURLOPT_URL(3) is the same 79*6236dae4SAndroid Build Coastguard Workerthat curl_url_set(3) uses. 80*6236dae4SAndroid Build Coastguard Worker 81*6236dae4SAndroid Build Coastguard Worker# ENCODING 82*6236dae4SAndroid Build Coastguard Worker 83*6236dae4SAndroid Build Coastguard WorkerThe string pointed to in the CURLOPT_URL(3) argument is generally 84*6236dae4SAndroid Build Coastguard Workerexpected to be a sequence of characters using an ASCII compatible encoding. 85*6236dae4SAndroid Build Coastguard Worker 86*6236dae4SAndroid Build Coastguard WorkerIf libcurl is built with IDN support, the server name part of the URL can use 87*6236dae4SAndroid Build Coastguard Workeran "international name" by using the current encoding (according to locale) or 88*6236dae4SAndroid Build Coastguard WorkerUTF-8 (when WinIDN is used; or a Windows Unicode build using libidn2). 89*6236dae4SAndroid Build Coastguard Worker 90*6236dae4SAndroid Build Coastguard WorkerIf libcurl is built without IDN support, the server name is used exactly as 91*6236dae4SAndroid Build Coastguard Workerspecified when passed to the name resolver functions. 92*6236dae4SAndroid Build Coastguard Worker 93*6236dae4SAndroid Build Coastguard Worker# DEFAULT 94*6236dae4SAndroid Build Coastguard Worker 95*6236dae4SAndroid Build Coastguard WorkerNULL. If this option is not set, no transfer can be performed. 96*6236dae4SAndroid Build Coastguard Worker 97*6236dae4SAndroid Build Coastguard Worker# SECURITY CONCERNS 98*6236dae4SAndroid Build Coastguard Worker 99*6236dae4SAndroid Build Coastguard WorkerApplications may at times find it convenient to allow users to specify URLs 100*6236dae4SAndroid Build Coastguard Workerfor various purposes and that string would then end up fed to this option. 101*6236dae4SAndroid Build Coastguard Worker 102*6236dae4SAndroid Build Coastguard WorkerGetting a URL from an external untrusted party brings several security 103*6236dae4SAndroid Build Coastguard Workerconcerns: 104*6236dae4SAndroid Build Coastguard Worker 105*6236dae4SAndroid Build Coastguard WorkerIf you have an application that runs as or in a server application, getting an 106*6236dae4SAndroid Build Coastguard Workerunfiltered URL can easily trick your application to access a local resource 107*6236dae4SAndroid Build Coastguard Workerinstead of a remote. Protecting yourself against localhost accesses is hard 108*6236dae4SAndroid Build Coastguard Workerwhen accepting user provided URLs. 109*6236dae4SAndroid Build Coastguard Worker 110*6236dae4SAndroid Build Coastguard WorkerSuch custom URLs can also access other ports than you planned as port numbers 111*6236dae4SAndroid Build Coastguard Workerare part of the regular URL format. The combination of a local host and a 112*6236dae4SAndroid Build Coastguard Workercustom port number can allow external users to play tricks with your local 113*6236dae4SAndroid Build Coastguard Workerservices. 114*6236dae4SAndroid Build Coastguard Worker 115*6236dae4SAndroid Build Coastguard WorkerAccepting external URLs may also use other protocols than http:// or other 116*6236dae4SAndroid Build Coastguard Workercommon ones. Restrict what accept with CURLOPT_PROTOCOLS_STR(3). 117*6236dae4SAndroid Build Coastguard Worker 118*6236dae4SAndroid Build Coastguard WorkerUser provided URLs can also be made to point to sites that redirect further on 119*6236dae4SAndroid Build Coastguard Worker(possibly to other protocols too). Consider your 120*6236dae4SAndroid Build Coastguard WorkerCURLOPT_FOLLOWLOCATION(3) and CURLOPT_REDIR_PROTOCOLS_STR(3) settings. 121*6236dae4SAndroid Build Coastguard Worker 122*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS% 123*6236dae4SAndroid Build Coastguard Worker 124*6236dae4SAndroid Build Coastguard Worker# EXAMPLE 125*6236dae4SAndroid Build Coastguard Worker 126*6236dae4SAndroid Build Coastguard Worker~~~c 127*6236dae4SAndroid Build Coastguard Workerint main(void) 128*6236dae4SAndroid Build Coastguard Worker{ 129*6236dae4SAndroid Build Coastguard Worker CURL *curl = curl_easy_init(); 130*6236dae4SAndroid Build Coastguard Worker if(curl) { 131*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 132*6236dae4SAndroid Build Coastguard Worker 133*6236dae4SAndroid Build Coastguard Worker curl_easy_perform(curl); 134*6236dae4SAndroid Build Coastguard Worker } 135*6236dae4SAndroid Build Coastguard Worker} 136*6236dae4SAndroid Build Coastguard Worker~~~ 137*6236dae4SAndroid Build Coastguard Worker 138*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY% 139*6236dae4SAndroid Build Coastguard Worker 140*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE 141*6236dae4SAndroid Build Coastguard Worker 142*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK on success or CURLE_OUT_OF_MEMORY if there was insufficient 143*6236dae4SAndroid Build Coastguard Workerheap space. 144*6236dae4SAndroid Build Coastguard Worker 145*6236dae4SAndroid Build Coastguard WorkerNote that curl_easy_setopt(3) does not parse the given string so given a 146*6236dae4SAndroid Build Coastguard Workerbad URL, it is not detected until curl_easy_perform(3) or similar is 147*6236dae4SAndroid Build Coastguard Workercalled. 148