Sending HTTP Request Using cURL Set-1
Last Updated :
01 Aug, 2021
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
Syntax:
curl --version
Output:
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
Release-Date: 2019-11-06
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.
curl http://138.68.158.87:30954/login.php
Note that instead of http://138.68.158.87:30954/login.php, you can specify the target on which you want to request the data.
Example :
HTML
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "UTF-8" >
< link rel = "stylesheet" href = "./style.css" >
</ head >
< body >
< hgroup >
< h1 >Admin panel</ h1 >
</ hgroup >
< form action = "" method = "post" >
< div class = "group" >
< input name = "username" type = "text" >
< span class = "highlight" ></ span >
< span class = "bar" ></ span >
< label >Username</ label >
</ div >
< div class = "group" >
< input name = "password" type = "password" >
< span class = "highlight" ></ span >
< span class = "bar" ></ span >
< label >Password</ label >
</ div >
< button type = "submit" class = "button buttonBlue" >
Login
< div class = "ripples buttonRipples" >
< span class = "ripplesCircle" ></ span >
</ div >
</ button >
</ form >
< script src =
</ script >
< script src = "./script.js" ></ script >
</ body >
</ html >
|
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://138.68.158.87:30954/login.php -v
- -u: Server user and password.
curl -u username:password http://138.68.158.87:30954/login.php -v
curl -u username:password -L http://138.68.158.87:30954/login.php -v
- -X: Specify request command to use.
curl -X GET http://138.68.158.87:30954/login.php -v
Note: By default curl uses GET request if we don’t specify the request command.
curl -u username:password -s -L http://138.68.158.87:30954/login.php -v
You can dive deeply into using different flags as per the need with the help of the -h flag.
curl -h
Similar Reads
How to Use Postman for Sending POST Requests?
Understanding how to send a POST request in Postman is a crucial skill for any developer or tester. POST requests are typically used for submitting data to a server, such as creating new resources or uploading files. What is a POST Request?A POST request is an HTTP request method used for sending da
4 min read
How to send a POST Request with PHP ?
In web development, sending POST requests is a common practice for interacting with servers and exchanging data. PHP, a versatile server-side scripting language, provides various approaches to accomplish this task. This article will explore different methods to send POST requests using PHP. Table of
3 min read
Create API Tester using Python Requests Module
Prerequisites: Python Requests module, API In this article, we will discuss the work process of the Python Requests module by creating an API tester. API stands for Application Programming Interface (main participant of all the interactivity). It is like a messenger that takes our requests to a syst
3 min read
How To Export Specific Request To File Using Postman?
Postman is a popular tool used for API testing and development. It provides a user-friendly interface to make HTTP requests, track responses, and organize API endpoints. One of the powerful features of Postman is the ability to export specific requests to a file. This is useful for sharing requests
3 min read
Postman - Working, HTTP Request & Responses
API...Application Programming Interface... If you're a developer then this word is nothing new for you... Being a developer, you know the importance of API in any kind of application. In simple terms, API is a defined set of rules with some defined methods of communication. With the help of API, sof
5 min read
Node.js http.ClientRequest.end() API
The http.ClientRequest.end() is  an inbuilt application programming interface of class ClientRequest within http module which is used to finish sending the request. If any parts of the body are unsent. Syntax: const request.end([data[, encoding]][, callback]) Parameters: This method takes the data a
2 min read
How to Post JSON Data using Curl ?
One can send the post data using curl (Client for URLs), a command line tool, and a library for transferring data with URLs. It supports various types of protocols. Most of the use cases of the curl command are posting JSON data to a server endpoint. CURLcURL stands for ( Client for URLs) and is a c
3 min read
Web Scraping using cURL in PHP
We all have tried getting data from a website in many ways. In this article, we will learn how to web scrape using bots to extract content and data from a website. We will use PHP cURL to scrape a web page, it looks like a typo from leaving caps lock on, but thatâs really how you write it. cURL is
2 min read
Node.js Http2ServerRequest.complete Method
The Http2ServerRequest.complete is an inbuilt application programming interface of class Http2ServerRequest within the http2 module which is used to check whether this request has been completed, aborted, or destroyed or not. Syntax: const request.complete Parameters: This method does not accept any
4 min read
How to create and send POST requests in Postman?
Postman is an API(application programming interface) development tool which helps to build, test and modify APIs. It can make various types of HTTP requests(GET, POST, PUT, PATCH), saving environments for later use, and convert save the API to code for various languages(like JavaScript, and Python).
2 min read