How to send a GET request using cURL?

You can send a GET request with cURL by passing the URL directly to the curl command. GET is cURL's default HTTP request method, so you do not need to specify it separately.

Send a GET request with cURL

The following command sends a GET request to ScrapingBee's HTTPBin endpoint:

curl "https://httpbin.scrapingbee.com/anything?json"

The output from the command is:

{
  "args": {
    "json": ""
  }, 
  "data": "", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Host": "httpbin.scrapingbee.com", 
    "L5D-Dst-Override": "scrapingbee-httpbin.httpbin.svc.cluster.local:80", 
    "User-Agent": "curl/8.5.0"
  }, 
  "json": null, 
  "method": "GET", 
  "origin": "105.164.128.44", 
  "url": "https://httpbin.scrapingbee.com/anything?json"
}

cURL sends the request and prints the response body in the terminal.

The JSON response includes details about the request received by HTTPBin, including the request method, URL, and headers.

In our test, the response included:

  "json": null, 
  "method": "GET", 
  "origin": "105.164.128.44", 
  "url": "https://httpbin.scrapingbee.com/anything?json"

The "method": "GET" value confirms that cURL sent a GET request.

Send a GET request with -X GET

You can also specify the request method explicitly with -X GET:

curl -X GET "https://httpbin.scrapingbee.com/anything?json"

The output is similar to the previous one, only that we have explicitly specified the method:

{
  "args": {
    "json": ""
  }, 
  "data": "", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Host": "httpbin.scrapingbee.com", 
    "L5D-Dst-Override": "scrapingbee-httpbin.httpbin.svc.cluster.local:80", 
    "User-Agent": "curl/8.5.0"
  }, 
  "json": null, 
  "method": "GET", 
  "origin": "105.164.128.44", 
  "url": "https://httpbin.scrapingbee.com/anything?json"
}

This sends the same GET request. However, -X GET is usually unnecessary because cURL uses GET by default when no other request method is specified.

Related curl web scraping questions: