cURL (Client Uniform Resource Locator)
Introduction
cURL was first released in 1997. It was originally named HTTP get and then became URL get before adopting the current name of cURL. The original author and lead developer is a Swedish developer Daniel Stenberg, who created cURL to automate the fetching of currency exchange rates.
What is cURL?
cURL stands for client URL and can be written as cURL which is used for file transfer with a URL syntax. It supports a number of protocols including HTTP, HTTPS, FTP, and many more. HTTP / HTTPS uses cURL to interact with APIs. cURL can be used on any machine and anywhere specially the basic cURL commands.
Where to use cURL?
cURL is used in a terminal or command prompt but the system should have it installed. Mostly used with Linux and it can be found in windows as well depending on the version that is being used.
cURL also has 2 products:
libcURL:
A free and easy to use client-side URL transfer library, supporting FTP, TPS, HTTPS, GOPHER, TELNET, DICT, FILE and LDAP, libcurl supports HTTPS certificates as well HTTP POST, HTTP PUT, FTP uploading and many more. libcURL is free, thread-safe, IPv6 compatible, feature rich, well supported and fast.
cURL:
A command line tool for getting or sending files using URL syntax, since curl uses libcURL, it supports a range of common internal protocols.
Installation
Installing Prebuilt binaries:
Many operating systems offer a “package repository” that is populated with software packages to install. From the curl download page you can also follow links to plain binary packages for popular operating systems.
Installing from package repository:
cURL and libCURL have been around for a very long time and most Linux distributions, BSD versions and other *nix versions have package repositories that allow you to install cURL packages.
Some common ones:
apt-get, yum, homebrew, cygwin,
Basic usage
cURL is a project and its primary purpose and focus is to make two products:
curl, the command-line tool
libcurl the transfer library with C API
Both the tool and the library do Internet transfers for resources specified as URLs using Internet protocols. Both these products are frequently used not only to drive thousands or millions of scripts and applications for an Internet connected world, but they are also widely used for server testing, protocol fiddling and trying out new things.
The command line tool is designed to work perfectly from scripts or other automatic means. It doesn’t feature any other GUI or UI other than mere text in and out
Request Headers and Body
The header callback is set with CURLOPT_HEADERFUNCTION:
The header_callback function must match this prototype:
size_t header_callback(char *ptr, size_t size, size_t nmemb, void *userdata);
This callback function gets called by libcurl as soon as a header has been received. ptr points to the delivered data, and the size of that data is size multiplied with nmemb. libcurl buffers headers and delivers only “full” headers, one by one, to this callback.
This callback should return the number of bytes actually taken care of. If that number differs from the number passed to your callback function, it signals an error condition to the library. This will cause the transfer to abort and the libcurl function used will return.
Comments
Post a Comment