Python code for Curl GET Request ExampleThis Python code snippet was generated automatically for the Curl GET Request example.
<< Back to the Curl GET Request example
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 GET example demonstrates how easy it is to make a GET request to the target server using Curl.
The server's response to our Curl request:
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.
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.
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.
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.
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.
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.
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:
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).