cURL With Proxy: Easy Tutorial

cURL with proxy, is the way to transfer data using a proxy server that acts as a transfer point between the client and the destination. Utilizing the cURL command with a proxy is the best way to start…

Retrieving Geo localized data results.
Access country-restricted platforms directly.
Start a web scraping task efficiently.

In this expository text, we will guide you step by step on how to use cURL or for simplicity’s sake curl.

Before starting, we recommend that you have a grounded understanding of what residential and mobile proxies are and how you would traditionally use them within browsers. This basic knowledge is going to go a long way in what will be a highly technical tutorial.

Are you a beginner? Learn to use proxies within Google Chrome proxy settings first.

First, What Is cURL?

cURL is a command used within the terminal for transferring data using a web page’s URL. The command first started to appear back in the 1990s and is popular with Linux systems. It supports the protocols HTTP/HTTPS/FTP/SCP/SOCKS4/5 and makes it compatible with most proxy types.

ProxyEmpire supports a wide range of protocols which include HTTP/HTTPS/SOCKS4/SOCKS5.

Linux operating systems like Ubuntu and Mac OS come packaged with a command window that accepts curl commands. Windows 10 started implementing curl right out of the box too but that does not guarantee that it will be installed already.

If your system does not function with cURL commands, you can download it here officially.

Ready to start scraping web data? Pick up a trial account by registering.

You can use curl directly which will expose both endpoints in your connection request AKA reveal your true location and IP address. To get started you would simply type this command which will output content from the web page URL.

If you want more information you can add -I which will propagate the header content that includes its creation date, content length, and server you are interacting with.

Notice that the cURL command will give you a status code for each URL you process. If a web page outputs the code 200 that means that it is functioning properly. In the example above we get a 301 redirect which you normally would see with domain names that have been changed.

Why?

Let’s take a moment to go back to where it all started. In the very beginning, we placed curl google.com within the command. The reason it gives us a redirect code is because by default cURL utilizes HTTP instead of HTTPS. Therefore, when it connected to Google it got a redirect message.

Simply put, you need to specify the protocol to use in order to get the right data.

cURL Is unforgiving in that each character is capital sensitive and the data you receive is greatly affected by what you put into the command line.

Setting Up cURL With Proxy

In this tutorial, we will be using residential and mobile proxies to facilitate requests within the curl command line. Typically, this means using a username/password authenticator. Make sure that your proxy partner like ProxyEmpire offers this authentication method.

Here’s what you’re going to need to get started…

1) Hostname / Proxy Address
2) Port
3) Username
4) Password

For those of you who are reading this who are already ProxyEmpire clients, you can find this information within your proxy manager dashboard after logging in.

Proxy Empire Proxy Manager

Remember something important…

Every time you change locations within the filter settings of your proxy panel you need to update your authentication when using cURL commands or for that matter any request. That is because the authentication information changes per location.

For the sake of this tutorial we’re going to set the user information as follows:

Proxy Address: 127.0.0.1
Port: 1234
Username: client
Password: 1q2w3e4r

These are not true details, but act as a demo for the tutorial.

Using cURL With The HTTP/HTTPS Protocols

The website we’re going to be using is called HTTPBIN which is a simple page that outputs the original IP address of the host that made the request. It’s a useful website if you want to quickly check a proxy or reveal your IP address without visiting proxy checkers full of ads.

There’s more than one way to use cURL with a proxy.

To get started what you need to do is open your terminal where we’re going to type in the following command that will propagate a list of command-line arguments.

It may seem like a daunting task to go through this huge list but to simplify everything all you have to do is look for the following line and memorize it.

The -x is just shorthand for -proxy but both can be used in the argument with the same results expected.

Remember how earlier we got a 301 redirect code because cURL by default uses HTTP instead of HTTPS? The same rules apply for both proxy protocols. If you do not specify the protocol then by default it will use HTTP. After you type in your information it should look something like this…

Note that when you switch locations within your proxy manager you will get a new username and that should be reflected in your command line argument. Also, if you change between mobile and residential proxies, your authentication information will change with it.

This is one of the most common reasons people get error messages when using backconnect proxies and setting up cURL with proxy from the panel.

Creating Environmental Variables To Use cURL With Proxy

Let’s suppose that you want to make dozens of requests using a single node from your proxy partner. That would require you to memorize and redundantly input the same authentication information for each request. There is a better way to make connections with cURL utilizing environments.

You have the option of two environments depending on the protocol you want to use.

Remember, setting up environment variables only works with Linux systems and Mac OS. This should not be a problem for people who are scraping data.

What we recommend is using a remote environment for this process anyway. It’s common for clients to set up a Linux environment on a rented server to initiate cURL requests using residential and mobile proxies. Just look for a VPS that has Ubuntu or Mint installed.

Now let’s look at what these environment variables look like.

http_proxy : The standard environment for cURL.
https_proxy: For clients who want to use the HTTPS protocol.

Open your terminal and set the environment before you execute any command-line arguments. You should type the following into your terminal.

Run one of these commands depending on the protocol you want to use and then you can proceed to use curl normally as you were before without having to re-authenticate each request. If you want to end the environment, you can simply use unset http_proxy or HTTPS depending on the protocol.

Setting Up A .curlrc File & Permanent Proxy

Users who want to professionally use cURL with proxy and extract mass amounts of data can take advantage of setting up a config file. This can also be used for Windows users who previously could not set an environment when using cURL command-line arguments.

In layman’s terms, this allows you to place the settings that you want in a text file within your systems directory and then call upon it to set your environment.

The advantages are obvious.

By creating multiple commands within the config file, you can save time and not worry about setting an environment each time. The settings are stored away and easily accessible when it’s time to implement that environment when making cURL requests.

The config file can be named anything just so it is a .curlrc file. If you are using a windows system you will want to use _curlrc and place the file in the %APPDATA% folder within your directory.

Within the file, add the command line arguments you want to use. For this example, we will put…

Now each time you make a cURL request it will use the proxy settings that you configured within the config file located within your systems directory. This method works on all operating systems.

If you receive an SSL error simply add a -k to the end of your syntax to ignore it.

Now each time you make a cURL request it will use the proxy settings that you configured within the config file located within your systems directory. This method works on all operating systems.

If you receive an SSL error simply add a -k to the end of your syntax to ignore it. 

How To Override .curlrc Config File Settings

Since a config file will use the settings you placed within it globally it may be necessary to override your settings or simply turn them off for one quick request. This is a simple procedure and can be done by typing in the basic syntax we used from the start.

If you want to use your local IP and ignore proxies altogether for a single request you can implement the following command-line argument.

By adding the asterisk and no proxy syntax within the terminal you can directly connect to the host without using the proxy settings that you set within the config file or environment.

Conclusion

Now you have the resources required to leverage cURL with a proxy which enables you to take advantage of not getting blocked when data mining and making requests. cURL Will continue to be one of the most powerful command lines for web scraping and data extraction.

If you’re a client of ProxyEmpire and need help using the right command line arguments within your terminal feel free to reach out to our live chat located in the bottom right-hand corner of your screen.

Learn More By Reading...