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?

6
  • 1
    Set the proxy address in ~/.curlrc as follows: proxy = <proxy_host>:<proxy_port>. Let me know if this works out and I will make it into a 'formal' answer...
    – andrew.46
    Jan 24 '18 at 8:16
  • @andrew.46 Great, it works. :)
    – Yves
    Jan 24 '18 at 8:44
  • What exactly did you put in ~/.bashrc?
    – muru
    Jan 24 '18 at 8:51
  • 1
    @muru export http_proxy="http://account:passwd@proxy.xxx.com:8080" export https_proxy=$http_proxy
    – Yves
    Jan 24 '18 at 8:58
  • @muru ...... Ooooo..... I made a mistake: I forgot the key word export...
    – Yves
    Jan 24 '18 at 8:59
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.

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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.