How to use CURL through a proxy?

SwiftProxy
By - Emily Chan
2025-01-10 20:58:35

CURL is a powerful command line tool for transferring data from a server. In some cases, you may need to use CURL through a proxy server in order to hide your real IP address, bypass certain network restrictions, or increase access speed. This article will detail how to use CURL through a proxy.

Understanding Proxy Servers

A proxy server is a server that acts as an intermediary between a client and a server. When you send a request through a proxy server, the request is first sent to the proxy server, which then forwards it to the target server. In this way, the target server will see the IP address of the proxy server instead of your real IP address.

Setting up a proxy server

Before using CURL through a proxy, you need to know the proxy server's address, port, and possibly username and password (if the proxy requires authentication).

1‌. Basic Usage‌:

To use CURL through an HTTP proxy, you can use the -x or --proxy option to specify the proxy server address and port. For example:

curl -x http://proxy.example.com:8080 http://example.com

Here, http://proxy.example.com:8080 is the address and port of the proxy server, and http://example.com is the target URL you want to access.

‌2. Use HTTPS proxy‌

If you need to access HTTPS websites through HTTPS proxy, you can specify it like this:

curl -x https://proxy.example.com:8080 https://example.com

3‌. Proxy with authentication‌

If the proxy server requires a username and password for authentication, you can specify it using the -U or --proxy-user option. For example:

curl -x http://proxy.example.com:8080 -U username http://example.com

4. Using a SOCKS proxy

CURL also supports connecting through a SOCKS proxy. You need to specify the socks5:// protocol. For example:

curl -x socks5://proxy.example.com:1080 http://example.com

5. Set environment variables

If you don't want to specify a proxy every time you use CURL, you can set the environment variables HTTP_PROXY, HTTPS_PROXY or ALL_PROXY. For example:

export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=https://proxy.example.com:8080
curl http://example.com

Notes

  1. Proxy server stability: Choose a stable proxy server to avoid connection interruptions or data transmission failures.
  2. Proxy server speed: Choose a faster proxy server to improve data transmission efficiency.
  3. Proxy server security: Make sure the proxy server is trustworthy to avoid data leakage or attacks.

Conclusion

Using CURL through a proxy is a flexible and powerful way to help you bypass network restrictions, hide your real IP address, or increase access speed. This can be easily achieved by simply specifying the proxy server's address, port, and possible authentication information in the CURL command.

About the author

SwiftProxy
Emily Chan
Lead Writer at Swiftproxy
Emily Chan is the lead writer at Swiftproxy, bringing over a decade of experience in technology, digital infrastructure, and strategic communications. Based in Hong Kong, she combines regional insight with a clear, practical voice to help businesses navigate the evolving world of proxy solutions and data-driven growth.
The content provided on the Swiftproxy Blog is intended solely for informational purposes and is presented without warranty of any kind. Swiftproxy does not guarantee the accuracy, completeness, or legal compliance of the information contained herein, nor does it assume any responsibility for content on thirdparty websites referenced in the blog. Prior to engaging in any web scraping or automated data collection activities, readers are strongly advised to consult with qualified legal counsel and to review the applicable terms of service of the target website. In certain cases, explicit authorization or a scraping permit may be required.
Join SwiftProxy Discord community Chat with SwiftProxy support via WhatsApp Chat with SwiftProxy support via Telegram
Chat with SwiftProxy support via Email