CURL: Learn how to Use CURL in Simple Way

CURL or cURL. is a software providing library and command-line tools for transferring data in various protocols. It is supported for Windows, Linux, mac OS as well as other operating systems. In this article you will learn how to use curl in a very simple way.

CURL supports HTTP, HTTPS, FTP, and other protocols. It is easy to use and command-line friendly. You can embed it in your software project for free. You can this software in https://curl.haxx.se/.

Installation on Windows

Head to https://curl.haxx.se/windows/ and I recommend the x64 bit version. The filename is called curl-x.x.x_x-wind64-mingw.zip. Head to Download Folder and extract the file.

In extracted curl directory, you will find curl in the bin directory. You can embed curl to your C/C++ project from include and lib. Basically, everything you need to know is in the directory. To use it. Go to the bin directory and tab File -> Powershell

Installation on Ubuntu / Debian Install

CURL is preinstalled in Ubuntu 18.04. If not, type in command-line:-

juju@juju-pc:~$ sudo apt install curl

Installation Arch Linux

[juju@juju-pc ~]$ pacman -S curl

Installation on RedHat 7

[juju@juju-pc ~]$ sudo yum install curl

Using Curl

To check the version of curl type:-

$ curl --version
curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.0g zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Release-Date: 2018-01-24
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL 

The first line is curl x64 gnu version. My PC is running Ubuntu 18.04 and the installed version is 7.58.0. This is normal. The most important part is that it must support the encryption layer. OpenSSL is required

The last line is supported protocols.  You can use curl to fetch an HTTP website:-

$ curl example.com
<!doctype html>
<html>
<head>
    <title>Example Domain</title>
--- Omitted results ---

To view HEAD without the message body

$ curl --head example.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html; charset=UTF-8
Date: Mon, 24 Dec 2018 14:42:59 GMT
Etag: "1541025663+ident"
Expires: Mon, 31 Dec 2018 14:42:59 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (bsa/EB18)
X-Cache: HIT
Content-Length: 1270

The output will be an HTML. You can use curl to fetch HTTPS URLS

$ curl https://example.com

You can use curl to retrieve files from FTP website. Curl can also list directory files in ftp site.

$ curl ftp://example.com/README

To understand how curl interact with servers. You simply type

$ curl --verbose ftp://example.com/README

Curl support fetching multiple URL at the same time

$ curl example1.com example2.com

CURL is supporting ipv6 protocol!

$ curl "http://[1001:1570:2252:1::20]/"

If there is authenticated website require basic HTTP login

$ curl http://username:password@website.com

You can use curl behind proxy. We know that proxy is frustrating. This is a simple way:-

If proxy does not require authentication:-

$ curl -x my-proxy:888 ...

Where -x represent the proxy., type your proxy address in my-proxy, and replace 888 with your proxy number. If your proxy requires certain authentication, do the following

$ curl -U user:passwd -x my-proxy:888 ...

-U represent the proxy username and password. If you went to exclude certain URL from the proxy

$ curl --noproxy URL1,URL2 -x my-proxy:888 ...

If your proxy is socks proxy, do the following

  1. SOCKS4
  2. SOCKS5
$ curl --socks4 -x my-proxy:888 ...
$ curl --socks5 -x my-proxy:888 ...

In the end. I hope you learned how to use curl. I will keep adding more tutorials here.