CURLOPT_URL.3 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.haxx.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" **************************************************************************
  22. .\"
  23. .TH CURLOPT_URL 3 "17 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options"
  24. .SH NAME
  25. CURLOPT_URL \- provide the URL to use in the request
  26. .SH SYNOPSIS
  27. #include <curl/curl.h>
  28. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_URL, char *URL);
  29. .SH DESCRIPTION
  30. Pass in a pointer to the \fIURL\fP to work with. The parameter should be a
  31. char * to a zero terminated string which must be URL-encoded in the following
  32. format:
  33. scheme://host:port/path
  34. For a greater explanation of the format please see RFC3986.
  35. libcurl doesn't validate the syntax or use this variable until the transfer is
  36. issued. Even if you set a crazy value here, \fIcurl_easy_setopt(3)\fP will
  37. still return \fICURLE_OK\fP.
  38. If the given URL is missing a scheme name (such as "http://" or "ftp://" etc)
  39. then libcurl will make a guess based on the host. If the outermost sub-domain
  40. name matches DICT, FTP, IMAP, LDAP, POP3 or SMTP then that protocol will be
  41. used, otherwise HTTP will be used. Since 7.45.0 guessing can be disabled by
  42. setting a default protocol, see \fICURLOPT_DEFAULT_PROTOCOL(3)\fP for details.
  43. Should the protocol, either that specified by the scheme or deduced by libcurl
  44. from the host name, not be supported by libcurl then
  45. \fICURLE_UNSUPPORTED_PROTOCOL\fP will be returned from either the
  46. \fIcurl_easy_perform(3)\fP or \fIcurl_multi_perform(3)\fP functions when you
  47. call them. Use \fIcurl_version_info(3)\fP for detailed information of which
  48. protocols are supported by the build of libcurl you are using.
  49. \fICURLOPT_PROTOCOLS(3)\fP can be used to limit what protocols libcurl will
  50. use for this transfer, independent of what libcurl has been compiled to
  51. support. That may be useful if you accept the URL from an external source and
  52. want to limit the accessibility.
  53. The \fICURLOPT_URL(3)\fP string will be ignored if \fICURLOPT_CURLU(3)\fP is
  54. set.
  55. \fICURLOPT_URL(3)\fP or \fICURLOPT_CURLU(3)\fP \fBmust\fP be set before a
  56. transfer is started.
  57. The host part of the URL contains the address of the server that you want to
  58. connect to. This can be the fully qualified domain name of the server, the
  59. local network name of the machine on your network or the IP address of the
  60. server or machine represented by either an IPv4 or IPv6 address. For example:
  61. http://www.example.com/
  62. http://hostname/
  63. http://192.168.0.1/
  64. http://[2001:1890:1112:1::20]/
  65. It is also possible to specify the user name, password and any supported login
  66. options as part of the host, for the following protocols, when connecting to
  67. servers that require authentication:
  68. http://user:password@www.example.com
  69. ftp://user:password@ftp.example.com
  70. smb://domain%2fuser:password@server.example.com
  71. imap://user:password;options@mail.example.com
  72. pop3://user:password;options@mail.example.com
  73. smtp://user:password;options@mail.example.com
  74. At present only IMAP, POP3 and SMTP support login options as part of the host.
  75. For more information about the login options in URL syntax please see RFC2384,
  76. RFC5092 and IETF draft draft-earhart-url-smtp-00.txt (Added in 7.31.0).
  77. The port is optional and when not specified libcurl will use the default port
  78. based on the determined or specified protocol: 80 for HTTP, 21 for FTP and 25
  79. for SMTP, etc. The following examples show how to specify the port:
  80. http://www.example.com:8080/ - This will connect to a web server using port
  81. 8080 rather than 80.
  82. smtp://mail.example.com:587/ - This will connect to a SMTP server on the
  83. alternative mail port.
  84. The path part of the URL is protocol specific and whilst some examples are
  85. given below this list is not conclusive:
  86. .IP HTTP
  87. The path part of an HTTP request specifies the file to retrieve and from what
  88. directory. If the directory is not specified then the web server's root
  89. directory is used. If the file is omitted then the default document will be
  90. retrieved for either the directory specified or the root directory. The exact
  91. resource returned for each URL is entirely dependent on the server's
  92. configuration.
  93. http://www.example.com - This gets the main page from the web server.
  94. http://www.example.com/index.html - This returns the main page by explicitly
  95. requesting it.
  96. http://www.example.com/contactus/ - This returns the default document from
  97. the contactus directory.
  98. .IP FTP
  99. The path part of an FTP request specifies the file to retrieve and from what
  100. directory. If the file part is omitted then libcurl downloads the directory
  101. listing for the directory specified. If the directory is omitted then
  102. the directory listing for the root / home directory will be returned.
  103. ftp://ftp.example.com - This retrieves the directory listing for the root
  104. directory.
  105. ftp://ftp.example.com/readme.txt - This downloads the file readme.txt from the
  106. root directory.
  107. ftp://ftp.example.com/libcurl/readme.txt - This downloads readme.txt from the
  108. libcurl directory.
  109. ftp://user:password@ftp.example.com/readme.txt - This retrieves the readme.txt
  110. file from the user's home directory. When a username and password is
  111. specified, everything that is specified in the path part is relative to the
  112. user's home directory. To retrieve files from the root directory or a
  113. directory underneath the root directory then the absolute path must be
  114. specified by prepending an additional forward slash to the beginning of the
  115. path.
  116. ftp://user:password@ftp.example.com//readme.txt - This retrieves the readme.txt
  117. from the root directory when logging in as a specified user.
  118. .IP SMTP
  119. The path part of a SMTP request specifies the host name to present during
  120. communication with the mail server. If the path is omitted then libcurl will
  121. attempt to resolve the local computer's host name. However, this may not
  122. return the fully qualified domain name that is required by some mail servers
  123. and specifying this path allows you to set an alternative name, such as
  124. your machine's fully qualified domain name, which you might have obtained
  125. from an external function such as gethostname or getaddrinfo.
  126. smtp://mail.example.com - This connects to the mail server at example.com and
  127. sends your local computer's host name in the HELO / EHLO command.
  128. smtp://mail.example.com/client.example.com - This will send client.example.com in
  129. the HELO / EHLO command to the mail server at example.com.
  130. .IP POP3
  131. The path part of a POP3 request specifies the message ID to retrieve. If the
  132. ID is not specified then a list of waiting messages is returned instead.
  133. pop3://user:password@mail.example.com - This lists the available messages for
  134. the user
  135. pop3://user:password@mail.example.com/1 - This retrieves the first message for
  136. the user
  137. .IP IMAP
  138. The path part of an IMAP request not only specifies the mailbox to list (Added
  139. in 7.30.0) or select, but can also be used to check the UIDVALIDITY of the
  140. mailbox, to specify the UID, SECTION (Added in 7.30.0) and PARTIAL octets
  141. (Added in 7.37.0) of the message to fetch and to specify what messages to
  142. search for (Added in 7.37.0).
  143. imap://user:password@mail.example.com - Performs a top level folder list
  144. imap://user:password@mail.example.com/INBOX - Performs a folder list on the
  145. user's inbox
  146. imap://user:password@mail.example.com/INBOX/;UID=1 - Selects the user's inbox
  147. and fetches message with uid = 1
  148. imap://user:password@mail.example.com/INBOX/;MAILINDEX=1 - Selects the user's inbox
  149. and fetches the first message in the mail box
  150. imap://user:password@mail.example.com/INBOX;UIDVALIDITY=50/;UID=2 - Selects
  151. the user's inbox, checks the UIDVALIDITY of the mailbox is 50 and fetches
  152. message 2 if it is
  153. imap://user:password@mail.example.com/INBOX/;UID=3/;SECTION=TEXT - Selects the
  154. user's inbox and fetches the text portion of message 3
  155. imap://user:password@mail.example.com/INBOX/;UID=4/;PARTIAL=0.1024 - Selects
  156. the user's inbox and fetches the first 1024 octets of message 4
  157. imap://user:password@mail.example.com/INBOX?NEW - Selects the user's inbox and
  158. checks for NEW messages
  159. imap://user:password@mail.example.com/INBOX?SUBJECT%20shadows - Selects the
  160. user's inbox and searches for messages containing "shadows" in the subject
  161. line
  162. For more information about the individual components of an IMAP URL please
  163. see RFC5092.
  164. .IP SCP
  165. The path part of a SCP request specifies the file to retrieve and from what
  166. directory. The file part may not be omitted. The file is taken as an absolute
  167. path from the root directory on the server. To specify a path relative to the
  168. user's home directory on the server, prepend ~/ to the path portion. If the
  169. user name is not embedded in the URL, it can be set with the
  170. \fICURLOPT_USERPWD(3)\fP or \fICURLOPT_USERNAME(3)\fP option.
  171. scp://user@example.com/etc/issue - This specifies the file /etc/issue
  172. scp://example.com/~/my-file - This specifies the file my-file in the
  173. user's home directory on the server
  174. .IP SFTP
  175. The path part of a SFTP request specifies the file to retrieve and from what
  176. directory. If the file part is omitted then libcurl downloads the directory
  177. listing for the directory specified. If the path ends in a / then a directory
  178. listing is returned instead of a file. If the path is omitted entirely then
  179. the directory listing for the root / home directory will be returned. If the
  180. user name is not embedded in the URL, it can be set with the
  181. \fICURLOPT_USERPWD(3)\fP or \fICURLOPT_USERNAME(3)\fP option.
  182. sftp://user:password@example.com/etc/issue - This specifies the file
  183. /etc/issue
  184. sftp://user@example.com/~/my-file - This specifies the file my-file in the
  185. user's home directory
  186. sftp://ssh.example.com/~/Documents/ - This requests a directory listing
  187. of the Documents directory under the user's home directory
  188. .IP SMB
  189. The path part of a SMB request specifies the file to retrieve and from what
  190. share and directory or the share to upload to and as such, may not be omitted.
  191. If the user name is not embedded in the URL, it can be set with the
  192. \fICURLOPT_USERPWD(3)\fP or \fICURLOPT_USERNAME(3)\fP option. If the user name
  193. is embedded in the URL then it must contain the domain name and as such, the
  194. backslash must be URL encoded as %2f.
  195. smb://server.example.com/files/issue - This specifies the file "issue" located
  196. in the root of the "files" share
  197. smb://server.example.com/files/ -T issue - This specifies the file "issue" will
  198. be uploaded to the root of the "files" share.
  199. .IP LDAP
  200. The path part of a LDAP request can be used to specify the: Distinguished
  201. Name, Attributes, Scope, Filter and Extension for a LDAP search. Each field
  202. is separated by a question mark and when that field is not required an empty
  203. string with the question mark separator should be included.
  204. ldap://ldap.example.com/o=My%20Organisation - This will perform a LDAP search
  205. with the DN as My Organisation.
  206. ldap://ldap.example.com/o=My%20Organisation?postalAddress - This will perform
  207. the same search but will only return postalAddress attributes.
  208. ldap://ldap.example.com/?rootDomainNamingContext - This specifies an empty DN
  209. and requests information about the rootDomainNamingContext attribute for an
  210. Active Directory server.
  211. For more information about the individual components of a LDAP URL please
  212. see RFC4516.
  213. .IP RTMP
  214. There's no official URL spec for RTMP so libcurl uses the URL syntax supported
  215. by the underlying librtmp library. It has a syntax where it wants a
  216. traditional URL, followed by a space and a series of space-separated
  217. name=value pairs.
  218. While space is not typically a "legal" letter, libcurl accepts them. When a
  219. user wants to pass in a '#' (hash) character it will be treated as a fragment
  220. and get cut off by libcurl if provided literally. You will instead have to
  221. escape it by providing it as backslash and its ASCII value in hexadecimal:
  222. "\\23".
  223. .RS 0
  224. The application does not have to keep the string around after setting this
  225. option.
  226. .SH ENCODING
  227. The string pointed to in the \fICURLOPT_URL(3)\fP argument is generally
  228. expected to be a sequence of characters using an ASCII compatible encoding.
  229. If libcurl is built with IDN support, the server name part of the URL can use
  230. an "international name" by using the current encoding (according to locale) or
  231. UTF-8 (when winidn is used).
  232. If libcurl is built without IDN support, the server name is used exactly as
  233. specified when passed to the name resolver functions.
  234. .SH DEFAULT
  235. There is no default URL. If this option isn't set, no transfer can be
  236. performed.
  237. .SH SECURITY CONCERNS
  238. Applications may at times find it convenient to allow users to specify URLs
  239. for various purposes and that string would then end up fed to this option.
  240. Getting a URL from an external untrusted party will bring reasons for several
  241. security concerns:
  242. If you have an application that runs as or in a server application, getting an
  243. unfiltered URL can easily trick your application to access a local resource
  244. instead of a remote. Protecting yourself against localhost accesses is very
  245. hard when accepting user provided URLs.
  246. Such custom URLs can also access other ports than you planned as port numbers
  247. are part of the regular URL format. The combination of a local host and a
  248. custom port number can allow external users to play tricks with your local
  249. services.
  250. Accepting external URLs may also use other protocols than http:// or other
  251. common ones. Restrict what accept with \fICURLOPT_PROTOCOLS(3)\fP.
  252. User provided URLs can also be made to point to sites that redirect further on
  253. (possibly to other protocols too). Consider your
  254. \fICURLOPT_FOLLOWLOCATION(3)\fP and \fICURLOPT_REDIR_PROTOCOLS(3)\fP settings.
  255. .SH PROTOCOLS
  256. All
  257. .SH EXAMPLE
  258. .nf
  259. CURL *curl = curl_easy_init();
  260. if(curl) {
  261. curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
  262. curl_easy_perform(curl);
  263. }
  264. .fi
  265. .SH AVAILABILITY
  266. POP3 and SMTP were added in 7.31.0
  267. .SH RETURN VALUE
  268. Returns CURLE_OK on success or CURLE_OUT_OF_MEMORY if there was insufficient
  269. heap space.
  270. Note that \fIcurl_easy_setopt(3)\fP won't actually parse the given string so
  271. given a bad URL, it will not be detected until \fIcurl_easy_perform(3)\fP or
  272. similar is called.
  273. .SH "SEE ALSO"
  274. .BR CURLOPT_VERBOSE "(3), " CURLOPT_PROTOCOLS "(3), "
  275. .BR CURLOPT_FORBID_REUSE "(3), " CURLOPT_FRESH_CONNECT "(3), "
  276. .BR curl_easy_perform "(3), "
  277. .BR CURLINFO_REDIRECT_URL "(3), " CURLOPT_PATH_AS_IS "(3), " CURLOPT_CURLU "(3), "