How do I use Curl to send a GET request?

Curl is a command-line tool used for transferring data using various protocols. It is a powerful tool that can be used to debug network-related issues, test APIs, and many more.

To send a GET request with curl, you use the following syntax:

curl http://example.com

This will send a GET request to the specified URL (http://example.com in this case) and output the result to the console.

You can also add headers to your request. Here's an example:

curl -H "Accept: application/json" http://example.com

In this example, -H is used to specify a request header. You can use it multiple times to specify multiple headers. Here, we're specifying that we want the Accept header to be application/json, which usually means we want the server to respond with JSON.

If you want to save the output of your curl command to a file instead of printing it to the console, you can use the -o option followed by the filename. Here's an example:

curl -o output.html http://example.com

This will save the output of the curl command to a file named output.html.

You can use the -I option if you want to fetch only the headers:

curl -I http://example.com

This will print out only the headers of the response. It's useful if you want to check if a web page is available, or to view the headers that are being sent back.

These are just a few examples of what you can do with curl. It's a very powerful tool with many more options and features.

Related Questions

Get Started Now

WebScraping.AI provides rotating proxies, Chromium rendering and built-in HTML parser for web scraping
Icon