On this page 28 sections
  1. What cURL is useful for
  2. Basic GET requests
  3. Download a file
  4. Inspect the full HTTP exchange
  5. Response headers vs response body
  6. HEAD requests
  7. Ignore certificate validation in a lab
  8. Set a custom User-Agent
  9. Send custom headers
  10. HTTP Basic Authentication
  11. GET parameters
  12. POST form data
  13. Send JSON data
  14. Cookies and sessions
  15. Save cookies for later requests
  16. HTTP methods
  17. Read API data
  18. Format JSON with jq
  19. Create an API resource
  20. Update an API resource
  21. Delete an API resource
  22. Follow redirects
  23. Show only the HTTP status code
  24. Understand common HTTP status codes
  25. Browser DevTools and cURL
  26. Network tab workflow
  27. A practical request workflow
  28. Key takeaway
01

What cURL is useful for

cURL is a command-line tool for sending requests to web servers and APIs. It is useful for testing endpoints, inspecting headers, sending authentication data, reproducing browser requests and interacting with APIs without opening a browser.

Show cURL help
curl -h
02

Basic GET requests

When no HTTP method is specified, cURL sends a GET request by default. This is the simplest way to retrieve the content returned by a web endpoint.

Basic GET request
curl https://sam0x.me
Request a specific page
curl https://sam0x.me/index.html
03

Download a file

The -O option saves the response using the remote filename. The -s option enables silent mode and removes progress output.

Download a remote file
curl -s -O https://sam0x.me/index.html
04

Inspect the full HTTP exchange

Verbose mode is one of the most useful cURL options when troubleshooting. The -v flag displays connection information, outgoing request headers and incoming response headers.

Verbose request
curl -v https://sam0x.me
05

Response headers vs response body

The -I option sends a HEAD request and returns only response headers. The -i option keeps the normal response body but includes the response headers above it.

Request only headers
curl -I https://sam0x.me
Show headers and body
curl -i https://sam0x.me
06

HEAD requests

A HEAD request is similar to GET but normally returns only metadata such as status code, content type, server information, cookies and caching headers. It is useful when you want to inspect an endpoint without downloading the full body.

Send HEAD request
curl -I https://sam0x.me
07

Ignore certificate validation in a lab

The -k option disables TLS certificate verification. This is useful in controlled environments using self-signed certificates, but it should not be treated as a normal production configuration.

Ignore TLS certificate validation
curl -k https://target1.sam0x.me
08

Set a custom User-Agent

The User-Agent header identifies the client making the request. Some applications change behaviour depending on this header, so cURL allows it to be modified with -A.

Set browser-like User-Agent
curl https://sam0x.me -A 'Mozilla/5.0'
09

Send custom headers

The -H option adds or overrides HTTP headers. This is frequently used for authorization tokens, content types, API keys and custom application headers.

Add a custom header
curl -H 'X-Lab: sam0x' https://api.sam0x.me
Send an Authorization header
curl -H 'Authorization: Basic YWRtaW46YWRtaW4=' https://target1.sam0x.me
10

HTTP Basic Authentication

HTTP Basic Authentication sends a username and password as an Authorization header. cURL can generate this header automatically with -u.

Basic authentication
curl -u admin:admin https://target1.sam0x.me
Credentials in the URL
curl https://admin:admin@target1.sam0x.me
11

GET parameters

GET parameters are appended to the URL after a question mark. Multiple parameters are separated with an ampersand. Quoting the full URL avoids shell interpretation issues.

Send a GET parameter
curl 'https://sam0x.me/search.php?search=linux'
Send multiple parameters
curl 'https://sam0x.me/search.php?q=nmap&page=2'
12

POST form data

The -d option sends request data. When used with standard key=value form data, cURL automatically uses POST unless another method is explicitly selected.

Send form data
curl -X POST -d 'username=admin&password=admin' https://target1.sam0x.me/login
POST without explicitly using -X
curl -d 'username=admin&password=admin' https://target1.sam0x.me/login
13

Send JSON data

APIs frequently expect JSON instead of traditional form data. The body is passed with -d and the Content-Type header tells the server that the payload is JSON.

POST JSON
curl -X POST https://api.sam0x.me/search -H 'Content-Type: application/json' -d '{"search":"linux"}'
14

Cookies and sessions

Web applications often use cookies to maintain sessions. The -b option sends cookies with the request, making it possible to reproduce an authenticated browser session from the command line.

Send a session cookie
curl -b 'PHPSESSID=sam0xsession123' https://target1.sam0x.me/dashboard
15

Save cookies for later requests

A useful extension to the basic cookie workflow is to save cookies returned by the server and reuse them later. -c writes cookies to a file, while -b can read them back.

Save cookies
curl -c cookies.txt -d 'username=admin&password=admin' https://target1.sam0x.me/login
Reuse saved cookies
curl -b cookies.txt https://target1.sam0x.me/dashboard
16

HTTP methods

The -X option explicitly selects the HTTP method. GET reads data, POST commonly creates or submits data, PUT updates a resource, and DELETE removes a resource when the API supports those operations.

Explicit GET
curl -X GET https://api.sam0x.me/users
POST
curl -X POST https://api.sam0x.me/users
PUT
curl -X PUT https://api.sam0x.me/users/1
DELETE
curl -X DELETE https://api.sam0x.me/users/1
17

Read API data

REST-style APIs usually expose resources through predictable URLs. A GET request can retrieve one entry or an entire collection.

Read one API entry
curl https://api.sam0x.me/city/london
Read all entries
curl -s https://api.sam0x.me/city/
18

Format JSON with jq

API responses are often returned as JSON. Piping the output to jq makes nested JSON easier to read and inspect.

Pretty-print JSON response
curl -s https://api.sam0x.me/city/ | jq
19

Create an API resource

A POST request is commonly used to create a new resource. The exact JSON fields depend on the API contract.

Create a city entry
curl -X POST https://api.sam0x.me/city/ -H 'Content-Type: application/json' -d '{"city_name":"Sam0x_City","country_name":"Lab"}'
20

Update an API resource

PUT is commonly used to replace or update an existing resource. Some APIs use PATCH for partial modifications instead, so always check the API behaviour.

Update an entry
curl -X PUT https://api.sam0x.me/city/london -H 'Content-Type: application/json' -d '{"city_name":"New_Sam0x_City","country_name":"Lab"}'
21

Delete an API resource

DELETE requests are normally used to remove a resource identified by its URL.

Delete an entry
curl -X DELETE https://api.sam0x.me/city/New_Sam0x_City
22

Follow redirects

Some endpoints respond with HTTP redirects instead of returning the final page directly. The -L option tells cURL to follow Location headers automatically.

Follow redirects
curl -L https://sam0x.me/login
23

Show only the HTTP status code

When scripting or quickly validating endpoints, it can be useful to ignore the response body and print only the status code.

Print status code only
curl -s -o /dev/null -w '%{http_code}\n' https://sam0x.me
24

Understand common HTTP status codes

cURL exposes the raw HTTP response, so understanding status codes is important. 200 generally means success, 301 and 302 indicate redirects, 401 indicates missing or invalid authentication, 403 means the server understood but refused the request, 404 indicates the resource was not found, and 500 indicates a server-side error.

25

Browser DevTools and cURL

Browser developer tools are useful for understanding the requests generated by a web application. The Network tab shows request methods, URLs, headers, cookies, parameters, request bodies and server responses. Once a request is understood, it can often be reproduced with cURL.

Open DevTools
F12
Open DevTools
CTRL+SHIFT+I
26

Network tab workflow

When analysing a request in DevTools, start with the method and URL, then inspect request headers, cookies, query parameters or request payload, and finally review the response status, headers and body. These elements map directly to cURL options.

27

A practical request workflow

A good cURL workflow is to begin with the simplest request possible and add options only when needed. First retrieve the endpoint, then enable verbose output, inspect headers, reproduce authentication or cookies, and finally recreate the exact request body.

1. Basic request
curl https://target1.sam0x.me
2. Inspect the exchange
curl -v https://target1.sam0x.me
3. Include headers in output
curl -i https://target1.sam0x.me
4. Reproduce a POST request
curl -X POST -H 'Content-Type: application/json' -d '{"search":"nmap"}' https://target1.sam0x.me/api/search
28

Key takeaway

cURL is most useful when you think in terms of HTTP rather than memorising flags. Identify the method, URL, headers, authentication, cookies and body of a request, then translate each part into the corresponding cURL option.