10 cURL Command Usage with Real-Time Example

cURL is a command-line instrument that lets you retrieve or ship knowledge utilizing URL syntax.

Should you work as a developer or within the help function, you ought to be conscious of this cURL command utilization to troubleshoot net purposes. cURL is a cross-platform utility that you need to use on Home windows, MAC, and UNIX.

Following are among the mostly used syntax with an instance that will help you.

Confirm which you can hook up with the URL

Should you’re on a UNIX system and also you’re making an attempt to connect with the exterior URL, the very first thing you will wish to do is test if you happen to can entry the URL by way of curl.

curl yoururl.com

No output is generated. Nonetheless, if the server fails to attach, you’ll get errors similar to “Unable to resolve the host.”

[root@gf-lab tmp]# curl helloitdoesntexist.com
curl: (6) Couldn't resolve host: helloitdoesntexist.com; Unknown error
[root@gf-lab tmp]#

Save URL/URI output to a file

If you might want to retailer the URL or URI content material in a selected file, you need to use the next syntax

curl https://yoururl.com > yoururl.html


[root@gf-lab tmp]# curl https://gf.dev > /tmp/gfhtml
  % Whole    % Obtained % Xferd  Common Velocity   Time    Time     Time  Present
                                 Dload  Add   Whole   Spent    Left  Velocity
100 18557    0 18557    0     0  72565      0 --:--:-- --:--:-- --:--:-- 72772
[root@gf-lab tmp]#

The instance above will save all contents of gf.dev to /tmp/gf.html

Present request and response header

Should you run into points and wish to validate, you get the anticipated request and response header.

curl -v yoururl.com


[root@gf-lab tmp]# curl -v https://geekflare.com
* About to attach() to geekflare.com port 443 (#0)
*   Making an attempt
* Linked to geekflare.com ( port 443 (#0)
* Initializing NSS with certpath: sql:/and many others/pki/nssdb
*   CAfile: /and many others/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection utilizing TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
* Server certificates:
* 	topic: CN=ssl371609.cloudflaressl.com,OU=PositiveSSL Multi-Area,OU=Area Management Validated
* 	begin date: Nov 07 00:00:00 2019 GMT
* 	expire date: Could 15 23:59:59 2020 GMT
* 	frequent title: ssl371609.cloudflaressl.com
* 	issuer: CN=COMODO ECC Area Validation Safe Server CA 2,O=COMODO CA Restricted,L=Salford,ST=Higher Manchester,C=GB
> GET / HTTP/1.1
> Consumer-Agent: curl/7.29.0
> Host: geekflare.com
> Settle for: */*
< HTTP/1.1 200 OK
< Date: Sat, 09 Nov 2019 19:41:37 GMT
< Content material-Sort: textual content/html; charset=UTF-8
< Switch-Encoding: chunked
< Connection: keep-alive
< Set-Cookie: __cfduid=d2ce6cd359ebc0b6eb5ff3a454ed042021573328497; expires=Solar, 08-Nov-20 19:41:37 GMT; path=/; area=.geekflare.com; HttpOnly; Safe
< Range: Settle for-Encoding
< Hyperlink: <https://geekflare.com/wp-json/>; rel="https://api.w.org/"
< Hyperlink: <https://geekflare.com/>; rel=shortlink
< X-SRCache-Fetch-Standing: HIT
< X-SRCache-Retailer-Standing: BYPASS
< X-Body-Choices: SAMEORIGIN
< X-Powered-By: EasyEngine v4.0.12
< Through: 1.1 google
< CF-Cache-Standing: DYNAMIC
< Strict-Transport-Safety: max-age=15552000; preload
< X-Content material-Sort-Choices: nosniff
< Alt-Svc: h3-23=":443"; ma=86400
< Count on-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
< Server: cloudflare
< CF-RAY: 533243e4bcd4bbf4-LHR

Obtain at a restrict pace

In case you are doing optimization and wish to see how a lot time it takes to obtain at a sure pace you may:-

curl –-limit-rate 2000B


curl –-limit-rate 2000B https://gf.dev

Use a proxy to attach

Very helpful if you happen to work on the DMZ server the place you need to hook up with the skin world by way of a proxy.

curl --proxy yourproxy:port https://yoururl.com

Check URL with injecting header

You should use curl by inserting a header together with your knowledge to check or repair the precise drawback. Let’s have a look at the next instance to request with Content material-Sort.

curl --header 'Content material-Sort: software/json' http://yoururl.com

Doing the above asks curl to move Content material-Sort as software/json within the request header.

Present reply header solely

In case you are troubleshooting and wish to shortly test the response header, you need to use the next syntax.

curl --head http://yoururl.com


[root@gf-lab tmp]# curl --head https://chandan.io
HTTP/1.1 200 OK
Date: Sat, 09 Nov 2019 19:51:23 GMT
Content material-Sort: textual content/html
Connection: keep-alive
Set-Cookie: __cfduid=d3cb2c7b8e566ad99c870b0af12b0f1eb1573329083; expires=Solar, 08-Nov-20 19:51:23 GMT; path=/; area=.chandan.io; HttpOnly
X-GUploader-UploadID: AEnB2Uo96JhvJmR2zYUL-Ndh2ta3UD_ykQAB5C7O8cjZQhCf-GxHQ0MsodSzRnl3guSN3ywAYNjtWcPXfwDXjLg3bQ-P5vQMOA
Expires: Sat, 09 Nov 2019 20:51:23 GMT
Cache-Management: public, max-age=3600
Final-Modified: Mon, 06 Aug 2018 10:45:47 GMT
x-goog-generation: 1533552347482034
x-goog-metageneration: 1
x-goog-stored-content-encoding: id
x-goog-stored-content-length: 24620
x-goog-hash: crc32c=DpDPAQ==
x-goog-hash: md5=cIP/3rusdUx12Zla1kf1yA==
x-goog-storage-class: MULTI_REGIONAL
Settle for-Ranges: bytes
CF-Cache-Standing: DYNAMIC
Count on-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 53325234dc2fbb9a-LHR

[root@gf-lab tmp]#

Join the HTTPS/SSL URL and ignore any SSL certificates errors

Once you attempt to entry an SSL/TLS certificates secured URL and if it’s the incorrect certificates or if the CN doesn’t match, you get the next error.

curl: (51) Unable to speak securely with peer: requested area title doesn't match the server's certificates.

Excellent news, you may instruct cURL to disregard the cert error --insecure flag.

curl --insecure https://yoururl.com

Join by way of a selected protocol (SSL/TLS)

Very helpful for testing whether or not a specific URL can carry out a handshake over a selected SSL/TLS protocol.

To attach with SSL v3

curl --sslv3 https://yoururl.com

and for various TLS variations

curl --tlsv1 https://instance.com
curl --tlsv1.0 https://instance.com
curl --tlsv1.1 https://instance.com
curl --tlsv1.2 https://instance.com
curl --tlsv1.3 https://instance.com

Obtain file from FTP server

You may as well use curl to obtain the file by coming into your username and password.

curl -u consumer:password -O ftp://ftpurl/type.css

You possibly can at all times use “-v” with any syntax to print in verbose mode.

Use host header

The host header is beneficial for testing the goal URL over IP when the requested content material is simply out there if the host header matches. Or if you wish to check the appliance utilizing load balancer IP/URL.

curl --header 'Host: targetapplication.com'

What about utilizing cURL on-line?

Sure, you may with the next instruments. You possibly can run cURL remotely.

On-line CURL – a light-weight instrument to get the URL on-line and the flexibility so as to add the next choices.


cURL command line builder – this one is totally different. It helps you construct the curl command the place you may enter info in a pleasant consumer interface, and on the backside you get the cURL command.

curl builder

cURL is a helpful utility to resolve a real-time connection drawback, and I hope the above helps you. If you wish to be taught extra, I like to recommend the Linux Command Line Fundamentals on-line course.

Rate this post
Leave a Comment