In this article, I am going to show you how to use a proxy with cURL.


Getting started

A proxy server acts as a gateway between your computer and the internet. It may provide better privacy, security, and performance.

cURL supports both HTTP and SOCKS proxies. These proxies can work with HTTP, HTTPS, and FTP protocols out of the box.

To specify a proxy that you want to use with cURL, you need to use the -x or --proxy option followed by the proxy address which is in the form of protocol://host:port.

Example #1: Naked proxy

I use the term naked proxy to refer to proxies that do not require any authentication methods.

To get the main page from via the HTTP proxy at

$ curl -x

Similarly, with the SOCKS5 proxy at

$ curl -x socks5://

To get the main page from which requires basic authentication, you need to use the -u option followed by the credential which is in the form of user:password:

$ curl -x   -u user:password
$ curl -x socks5:// -u user:password

To read more about basic authentication, you can read the article 3 methods to use basic authentication with cURL.

Example #2: Protected Proxy

I use the term protected proxy to refer to proxies that require basic authentication to protect itself from abuse.

cURL provides the -U or --proxy-user option to let you specify the credential of a proxy server.

Okay, you can give it a try:

$ curl -U proxy_user:proxy_password -x

You can even use a protected proxy to access a protected destination resource:

$ curl -U proxy_user:proxy_password -x -u user:password


Using a proxy with cURL is super simple. cURL also supports the environment variables such as http_proxy and HTTPS_PROXY, but I do not like this method so I do not introduce them in this article.