cURL (client URL) is an open-source command line tool, and a cross-platform library (libcurl
) used to transfer data between servers, distributed to nearly all new operating systems. cURL programming is used almost everywhere where sending or receiving data through internet protocols is required.
This article gives you an overview of cURL.
For a detailed explanation, see our blog post.
To use curl, write curl followed by the URL. This sends a GET request.
curl https://httbin.org/get
To send a POST request to a URL, the -d
(or –data
) flag is used:
curl -d "name=something&value=somethingelse" https://jsonplaceholder.typicode.com/posts/
Sending such a request should return:
{
"name": "something",
"value": "somethingelse",
"id": 101
}
We can also send POST requests in JSON form by adding the header Content-Type: application/json
:
curl -H "Content-Type: application/json" --data "{\"data\":\"some data\"}" https://jsonplaceholder.typicode.com/posts/
Add -L
to follow redirects:
curl -L https://google.com
cURL can be used to connect to any destination through a proxy:
curl --proxy proxyaddress:port https://jsonplaceholder.typicode.com/
Credential details can be sent through the -U
flag.
curl --proxy proxy:port -U “username:password” https://jsonplaceholder.typicode.com/
Some websites will require authentication by themselves before they accept any connection request. A similar flag -u
is used for server authentication:
curl -u username:password https://jsonplaceholder.typicode.com/
If you wish to learn more about cURL, see our blog post.