curl Commands for Common HTTP Tasks
curl is a command-line HTTP client, and most day-to-day work with it comes down to a handful of tasks: fetching a URL, sending a body, attaching credentials, following a redirect, downloading a file, or adjusting how TLS is handled.
This page organizes those tasks so you can find the flag that changes behavior and understand what it does before you run it.
Which curl task are you solving?
Start from the goal, not the flag. The list below groups the common tasks covered on this page. Each item links to a focused walkthrough of the command and its options.
- Fetch a page or endpoint: send a GET request.
- Send a payload as JSON: POST JSON with the right content type.
- Attach credentials: send Basic Auth credentials.
- Save a response to disk: download a file.
- Let curl chase a 3xx response: follow redirects.
- Retrieve structured data: get JSON or get XML.
- Work with a development or self-signed endpoint: ignore invalid and self-signed certificates (with caution).
- Remove a resource: send a DELETE request.
- Add or override a request header: send an HTTP header.
Decision checklist before you run a curl command
Use this checklist to confirm you have the right shape of command before executing it:
- Method: does the endpoint expect GET, POST, DELETE, or another verb? The default is GET, so any other method needs to be set explicitly.
- Body: are you sending data? If so, decide whether it is JSON, form-encoded, or a file, and set the matching content type.
- Headers: does the API require an Authorization, Accept, or custom header? Add it explicitly rather than relying on defaults.
- Redirects: if the endpoint may return a 3xx, decide whether curl should follow it or you want to inspect the first response.
- Output: do you want the response printed to the terminal, saved to a file, or piped to another tool?
- TLS: is the certificate valid? Only relax certificate checks for endpoints you control or trust, and never as a default for production traffic.
Example: sending JSON with curl
A JSON POST combines three decisions: the method, the content type, and the body. The POST JSON walkthrough covers the exact command. At a high level, the command sets the request method to POST, declares the JSON content type via a header, and supplies the JSON payload as the request body.
A useful failure distinction: if the server rejects the request with a content-type or media-type error, the header is the likely culprit; if the server accepts the content type but reports a parse error, the body itself is malformed. Checking those two independently saves time when a JSON POST does not behave as expected.
Certificate bypass vs. genuine TLS failure
Ignoring invalid and self-signed certificates is a deliberate relaxation of TLS verification, not a fix for a broken connection. If a request fails because the certificate chain cannot be validated, that is the case the bypass option addresses. If the request fails because the host is unreachable, the port is closed, or the handshake is rejected for another reason, disabling certificate checks will not help and may hide the real problem. Reserve the bypass for endpoints you control or have independently verified, and keep verification enabled for anything else.
curl option map by task
The table below groups the options by the task they serve. Treat it as a field map: find your task, then confirm the option that changes behavior for that task.
- Request method: GET is the default; POST and DELETE need to be set explicitly.
- Request body: supply data for POST; choose JSON or form encoding to match the endpoint.
- Headers: add Authorization, Accept, Content-Type, or custom headers as needed.
- Redirects: decide whether curl should follow a 3xx response or you want to inspect it.
- Output: print to the terminal or save to a file.
- TLS: keep verification on by default; relax it only for trusted endpoints.
Frequently asked questions
Is GET the default method for curl?
Yes. If you do not specify a method, curl sends a GET request. Any other method, such as POST or DELETE, needs to be set explicitly. The GET request walkthrough shows the minimal command.
Why does a JSON POST sometimes fail with a content-type error?
A JSON POST needs both a JSON body and a header that declares the JSON content type. If the header is missing or wrong, the server may reject the request before it ever parses the body. Check the header first, then the body, to isolate the cause.
What happens if I do not tell curl to follow redirects?
curl returns the first response it receives, including a 3xx status, without automatically requesting the redirect target. If you want the final resource, enable redirect following. If you want to inspect the redirect chain, leave it off.
When is it appropriate to ignore certificate errors in curl?
Only for endpoints you control or have independently verified, such as a local development server with a self-signed certificate. Disabling certificate checks for production or third-party endpoints removes a protection against man-in-the-middle attacks and can mask the real cause of a connection failure.