CURLOPT_PROXY.md (4513B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_PROXY 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_HTTPPROXYTUNNEL (3) 9 - CURLOPT_PRE_PROXY (3) 10 - CURLOPT_PROXYPORT (3) 11 - CURLOPT_PROXYTYPE (3) 12 Protocol: 13 - All 14 Added-in: 7.1 15 --- 16 17 # NAME 18 19 CURLOPT_PROXY - proxy to use 20 21 # SYNOPSIS 22 23 ~~~c 24 #include <curl/curl.h> 25 26 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PROXY, char *proxy); 27 ~~~ 28 29 # DESCRIPTION 30 31 Set the *proxy* to use for transfers with this easy handle. The parameter 32 should be a char * to a null-terminated string holding the hostname or dotted 33 numerical IP address. A numerical IPv6 address must be written within 34 [brackets]. 35 36 To specify port number in this string, append :[port] to the end of the host 37 name. The proxy's port number may optionally (but discouraged) be specified 38 with the separate option CURLOPT_PROXYPORT(3). If not specified, libcurl 39 defaults to using port 1080 for proxies. 40 41 The proxy string may be prefixed with [scheme]:// to specify which kind of 42 proxy is used. 43 44 Using this option multiple times makes the last set string override the 45 previous ones. Set it to NULL to disable its use again. 46 47 The application does not have to keep the string around after setting this 48 option. 49 50 ## http:// 51 52 HTTP Proxy. Default when no scheme or proxy type is specified. 53 54 ## https:// 55 56 HTTPS Proxy. (Added in 7.52.0 for OpenSSL and GnuTLS Since 7.87.0, it also 57 works for mbedTLS, Rustls, Schannel and wolfSSL.) 58 59 This uses HTTP/1 by default. Setting CURLOPT_PROXYTYPE(3) to 60 **CURLPROXY_HTTPS2** allows libcurl to negotiate using HTTP/2 with proxy. 61 62 ## socks4:// 63 64 SOCKS4 Proxy. 65 66 ## socks4a:// 67 68 SOCKS4a Proxy. Proxy resolves URL hostname. 69 70 ## socks5:// 71 72 SOCKS5 Proxy. 73 74 ## socks5h:// 75 76 SOCKS5 Proxy. Proxy resolves URL hostname. 77 78 ## 79 80 Without a scheme prefix, CURLOPT_PROXYTYPE(3) can be used to specify which 81 kind of proxy the string identifies. 82 83 When you tell the library to use an HTTP proxy, libcurl transparently converts 84 operations to HTTP even if you specify an FTP URL etc. This may have an impact 85 on what other features of the library you can use, such as CURLOPT_QUOTE(3) 86 and similar FTP specifics that do not work unless you tunnel through the HTTP 87 proxy. Such tunneling is activated with CURLOPT_HTTPPROXYTUNNEL(3). 88 89 Setting the proxy string to "" (an empty string) explicitly disables the use 90 of a proxy, even if there is an environment variable set for it. 91 92 Unix domain sockets are supported for socks proxies since 7.84.0. Set 93 localhost for the host part. e.g. socks5h://localhost/path/to/socket.sock 94 95 When you set a hostname to use, do not assume that there is any particular 96 single port number used widely for proxies. Specify it. 97 98 When a proxy is used, the active FTP mode as set with *CUROPT_FTPPORT(3)*, 99 cannot be used. 100 101 Doing FTP over an HTTP proxy without CURLOPT_HTTPPROXYTUNNEL(3) set makes 102 libcurl do HTTP with an FTP URL over the proxy. For such transfers, common FTP 103 specific options do not work, for example CURLOPT_USE_SSL(3). 104 105 # Authentication 106 107 The proxy can also be specified with its associated credentials like for 108 ordinary URLs in the style: `scheme://username:password@hostname` 109 110 Alternatively, set them using CURLOPT_PROXYUSERNAME(3) and 111 CURLOPT_PROXYPASSWORD(3). 112 113 # Environment variables 114 115 libcurl respects the proxy environment variables named **http_proxy**, 116 **ftp_proxy**, **sftp_proxy** etc. If set, libcurl uses the specified proxy 117 for that URL scheme. For an "FTP://" URL, the **ftp_proxy** is 118 considered. **all_proxy** is used if no protocol specific proxy was set. 119 120 If **no_proxy** (or **NO_PROXY**) is set, it is the exact equivalent of 121 setting the CURLOPT_NOPROXY(3) option. 122 123 The CURLOPT_PROXY(3) and CURLOPT_NOPROXY(3) options override environment 124 variables. 125 126 # DEFAULT 127 128 NULL 129 130 # %PROTOCOLS% 131 132 # EXAMPLE 133 134 ~~~c 135 int main(void) 136 { 137 CURL *curl = curl_easy_init(); 138 if(curl) { 139 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/file.txt"); 140 curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy:80"); 141 curl_easy_perform(curl); 142 } 143 } 144 ~~~ 145 146 # HISTORY 147 148 Since 7.14.1 the proxy environment variable names can include the protocol 149 scheme. 150 151 Since 7.21.7 the proxy string supports the socks protocols as "schemes". 152 153 Since 7.50.2, unsupported schemes in proxy strings cause libcurl to return 154 error. 155 156 # %AVAILABILITY% 157 158 # RETURN VALUE 159 160 curl_easy_setopt(3) returns a CURLcode indicating success or error. 161 162 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 163 libcurl-errors(3).