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?
Perhaps the easiest way to get curl to use a proxy is to add the details into
~/.curlrc
file. The syntax is as follows:This can alternatively be set as an environmental variable but IMHO using
~/.curlrc
is the most direct and least error prone method.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.
The client
curl
(naturally) uses the librarylibcurl
under the hood.In the context of proxies the libcurl api documentation among other things states:
So if you set the environment variable accordingly,
libcurl
and consequentlycurl
will pick it up. Any explicitly set proxy (e.g. in.curlrc
or via--proxy
cmdline argument) overwrites the environment variable settings.