Sending GET Request with Curl

To make a GET request using Curl, run the curl command followed by the target URL. Curl automatically selects the HTTP GET request method unless you use the -X, --request, or -d command-line option. The target URL is passed as the first command-line option. To add additional HTTP headers, use the -H command line option. Curl automatically adds an Accept: */* request header if no additional headers are passed, which tells the server that the Curl client can accept data in any format. In this Curl GET example, we send a Curl request to the ReqBin echo URL. Click Run to execute the Curl GET Request example online and see the results.
Sending GET Request with Curl Run
curl https://reqbin.com/echo
Updated: Viewed: 79743 times

What is Curl?

Curl stands for Client for URLs, and it is a popular command-line tool for Linux, Windows, and macOS for transferring data over the network using HTTP, HTTPS, FTP, and SFTP protocols. You can make GET, POST, and HEAD requests to the server, retrieve HTTP headers, download HTML pages, upload files, submit forms, and more.

Basic Curl GET request example

Curl is effortless to use, and this basic Curl example demonstrates how easy it is to make a GET request to the target server using Curl.

Basic Curl GET request example
curl https://reqbin.com/echo

The server's response to our Curl request:

Server response to Curl request
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 643
      
[html code here]

How to send HTTP headers with a Curl GET request?

To make a GET request with HTTP headers, use the -H command-line option. You can pass as many HTTP headers with your Curl GET request as you like using the -H command line multiple times.

Curl GET Request Example with custom HTTP headers
curl https://reqbin.com/echo
   -H "Cache-Control: must-revalidate"
   -H "Pragma: no-cache"
   -H "Expires: 0"

How to get only HTTP headers using Curl?

To fetch only HTTP headers, use the -I command-line option. In this case, Curl will use the HTTP HEAD method instead of the GET request method and will not download the body of the HTTP response message.

Curl GET HTTP headers example
curl -I https://reqbin.com/echo

How to check if the target URL supports HTTP/2 using Curl?

By sending a Curl HEAD request along with the --http2 command line parameter, you can check if the target URL supports the HTTP/2 protocol.

Curl HTTP/2 support check
curl -I --http2 https://reqbin.com/echo

In the response, you will see the HTTP/2 200 status line if your server supports the HTTP/2 protocol or HTTP/1.1 200 otherwise.

How to tell Curl to follow redirects?

By default, Curl doesn't follow 300x redirects. You can force Curl to follow the redirects given in the Location header using the -L command-line option.

Curl GET Request Example with Follow Redirects option
curl -L https://reqbin.com/echo

How to get a specific range of bytes from a resource using Curl?

You can use the -r command-line option to get a specific range of resource bytes from the target URL.

Curl example to get a specific range of bytes
curl https://reqbin.com/echo
   -r 0-15000

How to send cookies along with a GET request using Curl?

You can send cookies to the server using the -b command-line option followed by a string with the cookie or the name of the file containing the cookies.

Curl GET Request Example with Cookies
curl https://reqbin.com/echo
   -b "session=eJwlzj0wMQG7eO4Q"

How to get JSON using Curl?

In this Curl get JSON example, we use the "Accept: application/json" header because without this header, the server may return data in a different format. The following is an example of getting JSON from a ReqBin echo URL:

Curl GET JSON example
curl https://reqbin.com/echo/get/json
   -H "Accept: application/json"

Limiting the maximum transfer rate for Curl GET requests

With the --limit-rate command-line parameter, you can limit the maximum transfer rate for uploading and downloading files. Speed is measured in bytes per second unless you specify otherwise with the suffix K (kilobytes), M (megabytes), or G (gigabytes).

Curl transfer rate limit example
curl https://reqbin.com/echo
   --limit-rate 50K

See also

Generate Code Snippets for Curl GET Request Example

Convert your Curl GET Request request to the PHP, JavaScript/AJAX, Node.js, Curl/Bash, Python, Java, C#/.NET code snippets using the ReqBin code generator.

// try get IpInfo ASAP! getIpInfo($.noop);