Basics of cURL

cURL, which stands for client URL, is a command line tool developers use to transfer data to and from a server using one of the network protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP )

cURL is a multiplatform tool that works in Linux, windows, and mac.

Basic cURL commands

Following are some of the basic cURL commands that help in different situations.

To fetch the content from the specified URL
curl https://httpbin.org/ will fetch the contents from the given website
To save the fetched content to a directory in the local system with the source name of the fetched file
curl -O <URL> is the command used for this purpose. For example, curl -O https://mohamedfawas.github.io/fazdp.jpg will fetch the image from the given source and save that image file in the local system with the same file name in the source directory.
Fetch the file mentioned in the above example, but save the file with a different name in the local directory.
curl -o <path to file in local system> <URL> is the command used here. For example, curl -o /test_folder/faz_pic.jpg https://mohamedfawas.github.io/fazdp.jpg will fetch the image from the given URL and save that image with the name specified by the user in the mentioned file directory

When there is a change in the protocol

In some cases, the URL we mentioned to cURL command may be redirected to another website, or there may be some changes in the website protocol. In this cases, use the command curl -L <URL>, this will specify to cURL that the requested page has moved to a different location. As a result, cURL will redo the request in a new place.

An example of the above-mentioned case
curl http://mohamedfawas.github.io/ won't fetch the data because the correct protocol of the given website is HTTPS. In this case, Use the command curl -L http://mohamedfawas.github.io/ to fetch the data.

To query response headers

curl -I <URL> command is used to analyze the response headers sent by a particular web server. This can help in web assessment.

Example

To view advanced connection details

curl -v <URL> shows many of the advanced details regards to the connection.

Thank you for reading my post.