Both private users and businesses use a variety of tools with proxies. Everyone tends to build a comprehensive tech stack to achieve the desired goals. One of the quite popular network tools is cURL. Many people are wondering whether they can use cURL with proxy.

If you are one of them, you’ve stumbled upon the perfect article for you. Today, we will tackle everything you need to know about cURL, including what it is, how to set it up with proxies, and whether it is suitable for reaching public data.

cURL defined

cURL is short for Client URL, and it is often referred to as either cURL or curl. In both cases, the term refers to a command-line tool. There is one thing that makes this command-line tool unique — it is capable of transferring data via network protocols.

The command-line tool uses a simple IRL syntax to enable servers to local storage data transfer. At the center of the tool, we have “libcurl”. It is a free client-side URL transfer library that powers cURL. Finally, you don’t have to be an expert to use cURL. The instructions are pretty much straightforward.

The default cURL protocol is HTTP. It means that if you don’t specify the protocol in the command syntax, cURL will use HTTP.  The list of support protocols is quite long, and it includes various DICT, FILE, and FTP protocols. cURL is available on all major platforms, including Linux, MacOS, and Windows.

Ways to set up cURLs with proxies

There are several ways to set up cURL with proxy. However, before we give you some examples, you need to know a couple of things. To set up cURL with proxy you will need username and password, protocol, port, and proxy server address. Once you have these, you can set up cURL in several ways. You can also learn more about the curl proxy scenarios.

Make sure to use the proxy switch

If you use the basic syntax, cURL will fetch the data from the specified website. To use cURL with proxy, you need to add the proxy switch. You can tell cURL that you are using a proxy by adding either -x or -proxy switch. Note that these commands are case-sensitive.

Here is how they look:

  • curl -x “[protocol://][host][:port]” [URL] [options]
  • curl -proxy “[protocol://][host][:port]” [URL] [options]

[URL] is the site you are trying to access through the proxy, and [host] is the proxy address.

If you are on the network that uses either digest or NTLM authentication, you will need to use a different switch. For digest, you will use -proxy-digest, and for NTLM, proxy-ntlm.

Add username and password

Some proxy servers require authentication. Despite popular belief, you can use cURL to fetch data from target servers through proxies with authentication methods. All you have to do is appropriately add username and password to cURL syntax.

Here is how the command would look like with added username and password:

curl -x “[protocol://username:password@][host][:port]” [URL] [options]

Enable insecure server connections

When using SSL, you might encounter numerous SSL certificate errors if the connection is insecure. However, there is a way to bypass it through the cURL setup. There is a specific switch -k, that disables SSL certificate errors and enables insecure server connections even when using SSL. The command line is the same, with -k at the end:

curl -x “[protocol://username:password@][host][:port]” [URL] -k

If on Linux or MacOS set environment variables

cURL enables you to use different proxies for http and https protocols. It can help you streamline your operations and save you a lot of time having to type username, password, proxy address, and port over and over again. Setting cURL environment variables is easy (note that these are system-wide settings):

  • export http_proxy=”[protocol://username:password@][host][:port]”
  • export https_proxy=”[protocol://username:password@][host][:port]”

Now you can run cURL as if you are fetching data without a proxy:

  • curl [URL],

And cURL will execute it through proxy. You can unset the variables by typing:

  • unset http_proxy
  • unset https_proxy

Edit _curlrc or .curlrc file

There is a way to tell cURL to always use proxy without setting the system-wide environment variables. If you use Linux or MacOS, you can navigate to the Home directory, where you will find the .curlrc file. Open it and add proxy=”[protocol://username:password@][host][:port]”.

Windows users can find _curlrc file in the %APPDATA% folder and add the same line to it.

Getting public data with cURLs and proxies

cURL is a special tool if you are interested in fetching publicly available data. It doesn’t matter how you set it up with proxies. You can use cURL to fetch publicly available data anytime you want. This is why cURL is a go-to network tool for many businesses and individuals interested in web scraping.

Conclusion

As you can see, cURL is a very flexible network tool with a lot of different switches you can use. The most important thing about it is that you can set up cURL with proxy and that it supports virtually all protocols. It means that you can use it no matter how specific your web scraping operation is.