CURLOPT_URL.3 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2021, 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.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 \- URL for this transfer
  26. .SH SYNOPSIS
  27. .nf
  28. #include <curl/curl.h>
  29. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_URL, char *URL);
  30. .fi
  31. .SH DESCRIPTION
  32. Pass in a pointer to the \fIURL\fP to work with. The parameter should be a
  33. char * to a null-terminated string which must be URL-encoded in the following
  34. format:
  35. scheme://host:port/path
  36. For a greater explanation of the format please see RFC3986.
  37. libcurl does not validate the syntax or use this variable until the transfer is
  38. issued. Even if you set a crazy value here, \fIcurl_easy_setopt(3)\fP will
  39. still return \fICURLE_OK\fP.
  40. If the given URL is missing a scheme name (such as "http://" or "ftp://" etc)
  41. then libcurl will make a guess based on the host. If the outermost sub-domain
  42. name matches DICT, FTP, IMAP, LDAP, POP3 or SMTP then that protocol will be
  43. used, otherwise HTTP will be used. Since 7.45.0 guessing can be disabled by
  44. setting a default protocol, see \fICURLOPT_DEFAULT_PROTOCOL(3)\fP for details.
  45. Should the protocol, either that specified by the scheme or deduced by libcurl
  46. from the host name, not be supported by libcurl then
  47. \fICURLE_UNSUPPORTED_PROTOCOL\fP will be returned from either the
  48. \fIcurl_easy_perform(3)\fP or \fIcurl_multi_perform(3)\fP functions when you
  49. call them. Use \fIcurl_version_info(3)\fP for detailed information of which
  50. protocols are supported by the build of libcurl you are using.
  51. \fICURLOPT_PROTOCOLS(3)\fP can be used to limit what protocols libcurl will
  52. use for this transfer, independent of what libcurl has been compiled to
  53. support. That may be useful if you accept the URL from an external source and
  54. want to limit the accessibility.
  55. The \fICURLOPT_URL(3)\fP string will be ignored if \fICURLOPT_CURLU(3)\fP is
  56. set.
  57. \fICURLOPT_URL(3)\fP or \fICURLOPT_CURLU(3)\fP \fBmust\fP be set before a
  58. transfer is started.
  59. The application does not have to keep the string around after setting this
  60. option.
  61. .SH ENCODING
  62. The string pointed to in the \fICURLOPT_URL(3)\fP argument is generally
  63. expected to be a sequence of characters using an ASCII compatible encoding.
  64. If libcurl is built with IDN support, the server name part of the URL can use
  65. an "international name" by using the current encoding (according to locale) or
  66. UTF-8 (when winidn is used; or a Windows Unicode build using libidn2).
  67. If libcurl is built without IDN support, the server name is used exactly as
  68. specified when passed to the name resolver functions.
  69. .SH DEFAULT
  70. There is no default URL. If this option is not set, no transfer can be
  71. performed.
  72. .SH SECURITY CONCERNS
  73. Applications may at times find it convenient to allow users to specify URLs
  74. for various purposes and that string would then end up fed to this option.
  75. Getting a URL from an external untrusted party will bring reasons for several
  76. security concerns:
  77. If you have an application that runs as or in a server application, getting an
  78. unfiltered URL can easily trick your application to access a local resource
  79. instead of a remote. Protecting yourself against localhost accesses is hard
  80. when accepting user provided URLs.
  81. Such custom URLs can also access other ports than you planned as port numbers
  82. are part of the regular URL format. The combination of a local host and a
  83. custom port number can allow external users to play tricks with your local
  84. services.
  85. Accepting external URLs may also use other protocols than http:// or other
  86. common ones. Restrict what accept with \fICURLOPT_PROTOCOLS(3)\fP.
  87. User provided URLs can also be made to point to sites that redirect further on
  88. (possibly to other protocols too). Consider your
  89. \fICURLOPT_FOLLOWLOCATION(3)\fP and \fICURLOPT_REDIR_PROTOCOLS(3)\fP settings.
  90. .SH PROTOCOLS
  91. All
  92. .SH EXAMPLE
  93. .nf
  94. CURL *curl = curl_easy_init();
  95. if(curl) {
  96. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  97. curl_easy_perform(curl);
  98. }
  99. .fi
  100. .SH AVAILABILITY
  101. POP3 and SMTP were added in 7.31.0
  102. .SH RETURN VALUE
  103. Returns CURLE_OK on success or CURLE_OUT_OF_MEMORY if there was insufficient
  104. heap space.
  105. Note that \fIcurl_easy_setopt(3)\fP will not actually parse the given string so
  106. given a bad URL, it will not be detected until \fIcurl_easy_perform(3)\fP or
  107. similar is called.
  108. .SH "SEE ALSO"
  109. .BR CURLOPT_VERBOSE "(3), " CURLOPT_PROTOCOLS "(3), "
  110. .BR CURLOPT_FORBID_REUSE "(3), " CURLOPT_FRESH_CONNECT "(3), "
  111. .BR curl_easy_perform "(3), "
  112. .BR CURLINFO_REDIRECT_URL "(3), " CURLOPT_PATH_AS_IS "(3), " CURLOPT_CURLU "(3), "