4

Today I configured the PC of my company to setup a proxy and it worked because I can wget web page via proxy.

What I did is set http_proxy, https_proxy and ftp_proxy in the ~/.bashrc and in the ~/.wgetrc.

However, when I tried to curl www.google.fr, it blocked and timeout.

curl --proxy $http_proxy www.google.fr worked as expected.

Is it possible to make curl use the proxy automatically?

Yves
  • 1,288
  • 6
  • 19
  • 34

3 Answers3

5

Perhaps the easiest way to get curl to use a proxy is to add the details into ~/.curlrc file. The syntax is as follows:

proxy = <proxy_host>:<proxy_port>

This can alternatively be set as an environmental variable but IMHO using ~/.curlrc is the most direct and least error prone method.

tetebueno
  • 163
  • 5
andrew.46
  • 38,003
  • 27
  • 156
  • 232
0

Some proxies require specific authentication headers to be set, so be aware of those as well. In my case, it's --proxy-ntlm in the example below:

curl -x webproxy.net:8080 -U usernaname:password http://google.com --proxy-ntlm

Bu there are other options:

--proxy-digest and --proxy-negotiate

Lastly, cURL has a super friendly doc page, so be sure to check it out.

K7AAY
  • 17,202
Ostati
  • 101
0

The client curl (naturally) uses the library libcurl under the hood.

In the context of proxies the libcurl api documentation among other things states:

Environment variables

libcurl respects the proxy environment variables named http_proxy, ftp_proxy, sftp_proxy etc. If set, libcurl will use the specified proxy for that URL scheme. So for a "FTP://" URL, the ftp_proxy is considered. all_proxy is used if no protocol specific proxy was set.

If no_proxy (or NO_PROXY) is set, it is the exact equivalent of setting the CURLOPT_NOPROXY option.

The CURLOPT_PROXY and CURLOPT_NOPROXY options override environment variables.

So if you set the environment variable accordingly, libcurl and consequently curl will pick it up. Any explicitly set proxy (e.g. in .curlrc or via --proxy cmdline argument) overwrites the environment variable settings.

Jan
  • 1,193
  • 11
  • 11