50% OFF Residential Proxies for 9 months — use code IPR50 at checkout

Get The Deal

In This Article

Back to blog

How to Send a cURL GET Request (With Parameters & Headers)

Tutorials

Vilius Dumcius

Last updated - ‐ 6 min read

Key Takeaways

  • Leverage cURL GET requests to fetch data with headers, params, and tokens.

  • Use -v for debugging, --compressed for smaller responses, and -I (capital “i”) to fetch only headers.

  • cURL works on all systems and is great for APIs and HTTP requests.

A cURL GET request retrieves data from a specified resource, usually a URL. GET requests are one of the most widely used HTTP methods, as they are used whenever you access something on the internet.

While you usually do that through a browser, the cURL GET command lets you bypass all the GUI drawing and collect only the HTML code data.

Getting Started With cURL

cURL comes pre-installed in many modern operating systems, such as Windows 10 and macOS. Some Linux distributions may have cURL available. However, you’ll often need to install it manually:

sudo apt-get install curl

You can also learn how to download curl file yourself. If your Windows operating system is older than 10, installing cURL manually will be required . Once that is complete, open up the Terminal (or Command Prompt in Windows) and check if cURL is working properly. A simple cURL command makes an HTTP request directly from your terminal:

curl --help

Sending a cURL GET Request

The cURL GET method is the default action whenever you type in “curl” and any URL, as such:

curl https://iproyal\.com

One important thing to remember is that cURL defaults to GET if you don't specify a method.

Alternatively, you can specify the GET method (by using -G or --get), which will always follow the structure of:

curl --get [url]

Additionally, you can add cURL query parameters by appending them directly to the URL. If you prefer to pass them as data fields, use the -G flag together with -d to include parameters in the URL instead of the request body. It’s helpful when you need to transfer data through the URL itself instead of sending it in the body.

curl --get -d "parameter=value" -d "parameter2=value2" -d "parameter=value3" https://iproyal\.com

Note that all data that is being sent with the GET request is added in quotation marks.

You can also send a cURL GET with parameters to several URLs at once. Actions will be performed on each URL in sequence.

curl --get -d "parameter=value" -d "parameter2=value2" -d "parameter=value3" https://iproyal\.com https://iproyal\.com/proxies-by-location/north-america/united-states/

Finally, if a website has redirects, you have to send a GET request with parameters to follow them. Otherwise, it'll only attempt to reach the defined URL(s). Use the -L parameter to follow redirects:

curl -G -L https://iproyal\.com

An important part of a cURL GET command is HTTP headers. Some websites may block requests with default GET request parameters. Setting HTTP headers, especially the user agent, may help evade the block:

curl --get -A "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0" https://iproyal\.com/

User agents are set with -A and a string that defines the agent. Using popular browser user agents is a great way to reduce the likelihood of getting blocked.

You can also retrieve headers from a website, along with the rest of the cURL GET body, by using the -i (short for “include”). Alternatively, you can use --head to ignore the cURL GET request body and retrieve the headers only:

curl --get -A "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0" --head https://iproyal\.com/

Ready to get started?
Register now

Retrieving Data in Specific Formats

You can create a cURL with parameters so that you receive data in a preferable format. JSON formats are frequently used without the cURL params, the data received is a jumbled mess:

curl -G -H "Accept: application/json" https://iproyal\.com

You'll be setting a parameter option with -H and entering "Accept: application/json". Note that it will only work if the server can respond in such a way. Many websites may not respond with a JSON format; however, it's quite common for APIs.

Authentication With cURL Request Parameters

Finally, to access some websites, you'll need to provide credentials. There are two main authentication options: usernames and passwords, or access tokens. The latter are included in the header as in the previous example:

curl -G -H "API-Access-Token: YOUR_TOKEN" https://iproyal\.com

For usernames and passwords, the cURL query parameter --user is used:

curl -G --user "USERNAME:PASSWORD" https://iproyal\.com

You can also include your username in a cookie, which may provide different content (especially when you're dealing with login or post-login pages):

curl -G --user "USERNAME:PASSWORD" --cookie "username=Tom" https://iproyal\.com

Handling Errors in cURL GET Requests

When a GET request using cURL fails, you need to know why. Use -v or --verbose to see the complete command line tool output:

curl -G -v https://wrong-url\.com

It shows complete request and response headers. You can also check HTTP status codes quickly with -I (capital “i”):

curl -I https://iproyal\.com

It sends a GET request using cURL, but only shows headers like HTTP/1.1 200 OK.

Here’s a successful example:

curl -I https://iproyal\.com

And here’s a failed one:

curl -I https://wrong-url\.com

Common cURL Errors

Error code Meaning
6 Couldn’t resolve host
7 Failed to connect to host
22 HTTP page not retrieved
28 Operation timed out
35 SSL connect error

You can run all these tests right from your terminal, making cURL a handy command-line tool for quick network checks.

Gzip Compression Support

To reduce download size, use:

curl --compressed https://iproyal\.com

It asks the server to send compressed data if supported. It saves time and bandwidth, but not all servers support it.

The compressed server’s response is unpacked by cURL automatically. It’s a great solution when working with APIs or large responses.

Making GET Requests to REST APIs

A common use of the cURL command is for REST APIs. APIs usually return data in JSON format and use tokens to authenticate.

Here’s how a common cURL example could look:

curl -G "https://api.example.com/data" \
-d "limit=10" \
-H "Authorization: Bearer YOUR_TOKEN"

Note that the slashes move the code to the following line in PowerShell. Different terminals may use different symbols for continuation lines.

It sends a GET request, limits results to 10, and uses token authentication. You’ll often need to set Accept: application/json, add access tokens, and use -G with -d to include query parameters in the URL.

cURL GET Request in Windows

To run a GET request on Windows:

  • Press “Win + R”, type “cmd”, and press “Enter” to open Command Prompt.
  • Try this command:
curl -G https://iproyal\.com

If you get an error like 'curl' is not recognized, here’s what you should do next:

  • Download cURL from the official site: https://curl.se/windows/
  • Unzip it.
  • Add the folder path to your PATH environment variable.
  • Restart Command Prompt

It should let you use cURL as a complete command-line tool on Windows. Once it’s set up, you’re good to go.

Conclusion

cURL is very useful for retrieving data from websites with the GET request method. You can also use other programs to automate the process. Here's a basic cURL GET example, which you can modify with the parameters we've outlined above:

curl --get -A "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0" https://iproyal\.com/

Sending a browser user agent should often be included, as you might get blocked otherwise.

Finally, we've only touched upon all of the available cURL GET params. You can find them all by typing in:

curl --help all

If you want to learn more about POST requests, we recommend our cURL POST request blog post. It digs deeper into the POST method with cURL and what you need to know about it.

Create Account
Share on
Article by IPRoyal
Meet our writers
Data News in Your Inbox

No spam whatsoever, just pure data gathering news, trending topics and useful links. Unsubscribe anytime.

No spam. Unsubscribe anytime.

Related articles