Sending HTTP Request Using cURL Set-1
Whenever we are dealing with HTTP requests, cURL simplifies our tasks to a great extent and is the easiest tool to get our hands dirty on.
cURL: It stands for “client URL” and is used in command line or scripts to transfer data. It is a great tool for dealing with HTTP requests like GET, POST, PUT, DELETE, etc. Although it provides us with the support of other internet protocols like HTTPS, FTP, SMTP, TELNET, we will be limiting it to HTTP in this article.
Pre-requisite: Install cURL properly as per your underlying operating system.
To check if it’s installed in your system or to know its version, the following command is executed in the command prompt
curl 7.67.0 (x86_64-pc-linux-gnu) libcurl/7.67.0 OpenSSL/1.1.1d zlib/1.2.11
brotli/1.0.7 libidn2/2.2.0 libpsl/0.20.2 (+libidn2/2.0.5) libssh2/1.8.0 nghttp2/1.41.0 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS brotli GSS-API HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets
We can see that the output states the version, release date, protocols, and other features of curl as –version flag was used.
Note: The output may differ based on the version and the underlying operating system.
GET request using cURL: Get request is the most commonly used HTTP request as it is used to request the data from the server about a particular target i.e website. Let’s start by executing a simple Get request.
Note that instead of http://220.127.116.11:30954/login.php, you can specify the target on which you want to request the data.
In this manner, you will get the entire output which will be the same if your query through the browser and the response from the server is rendered by your client browser and then shown to you in a simplified manner.
Note: If you will view the target source code, you will find the same output.
Many other flags can be used with the above query.
- -v: It is used to get verbose output.
curl http://18.104.22.168:30954/login.php -v
- -u: Server user and password.
curl -u username:password http://22.214.171.124:30954/login.php -v
- -L: Follow redirects.
curl -u username:password -L http://126.96.36.199:30954/login.php -v
- -X: Specify request command to use.
curl -X GET http://188.8.131.52:30954/login.php -v
Note: By default curl uses GET request if we don’t specify the request command.
- -s: Silent mode.
curl -u username:password -s -L http://184.108.40.206:30954/login.php -v
You can dive deeply into using different flags as per the need with the help of the -h flag.