curl - Download and Send Data over HTTP
The curl command communicates with web servers over HTTP and HTTPS from Command Prompt. You can download web pages and files, call web APIs, and check HTTP status codes without using a browser.
curl.exe is included with Windows 10 version 1803 and later and with Windows 11, so you can use it without installing anything.
Basic curl Syntax
curl [options] URL
If you specify only a URL, curl prints whatever the server returns to the console as-is.
curl https://example.com
Running where curl shows a path such as C:\Windows\System32\curl.exe, and curl --version shows the version. If it is not found, you may be on a version older than Windows 10 1803. If Git for Windows or similar software is installed, a different curl may be listed first. For where, see
In Windows PowerShell 5.1, curl is an alias for the Invoke-WebRequest cmdlet, and both the options and the results differ from this article. PowerShell 7 and later no longer have this alias, but typing curl.exe with the extension runs the real curl in any version. Quoting rules also differ in PowerShell. Command Prompt does not have this problem.
Save to a File (-o / -O)
To save the downloaded content to a file, specify the destination with -o.
curl -o page.html https://example.com
To reuse the file name at the end of the URL, use an uppercase -O.
curl -O https://example.com/files/report.pdf
In this example, report.pdf is saved in the current directory. See also
When you save with -o or -O, a file with the same name is overwritten without warning. If you run the command in a folder that contains important files, specify the destination path explicitly.
Follow Redirects (-L)
Short URLs and download URLs are sometimes redirected to another URL. By default curl does not follow the redirect, so add -L to fetch the final destination.
curl -L -o setup.zip https://example.com/download/latest
Adjust Progress and Error Output (-s / -S / -f)
curl shows a progress meter while downloading. To keep batch file logs clean, combine the following options.
| Option | Description |
|---|---|
-s | Hides the progress meter and error messages (silent) |
-S | Used with -s, shows a message only when an error occurs |
-f | On HTTP errors such as 404 or 500, exits with an error instead of saving the body |
Without -f, a 404 error page (an HTML page describing the error) is saved to the file as if the download had succeeded. The combination -fsSL is commonly used in scripts.
curl -fsSL -o setup.zip https://example.com/download/latest
Check Only the HTTP Headers (-I)
With -I, curl does not fetch the body and displays only the HTTP headers (status, modification date, and so on).
curl -I https://example.com

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超 入門

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門
You can check whether a site responds and how large a file is without downloading it. The output varies by server.
Call a Web API (-H / -d / -X)
GET with a Header (-H)
-H adds any HTTP header. It is used, for example, to send an API token.
curl -H "Authorization: Bearer %API_TOKEN%" https://api.example.com/v1/items
Writing a token directly in the command can leak it through command history or screen sharing. Storing it in an environment variable and referencing it, as in this example, is recommended. For environment variables, see
.POST Data (-d)
Specifying data with -d automatically makes the method POST. When sending JSON, also add a Content-Type header.
curl -X POST -H "Content-Type: application/json" -d "{\"name\":\"sample\",\"count\":3}" https://api.example.com/v1/items
In Command Prompt, only double quotes " can enclose a string, so double quotes inside the JSON are escaped as \".
For longer JSON, save it to a file and load it with @filename. This avoids the escaping work and typing mistakes.
curl -X POST -H "Content-Type: application/json" -d @data.json https://api.example.com/v1/items
Specifying -d already makes the method POST, so -X POST can be omitted. Use it for other methods such as -X PUT or -X DELETE.
If you type non-ASCII characters such as Japanese directly into Command Prompt, they may be sent garbled because of the code page. For data with such characters, save it as UTF-8 and pass it with -d @data.json. See
Get the HTTP Status Code (-w)
-w (write-out) prints information about the transfer. %{http_code} is the HTTP status code.
curl -s -o NUL -w "%{http_code}" https://example.com
-o NUL discards the body (NUL is a special device name that discards anything written to it).
In a batch file, % has a special meaning, so -w "%{http_code}" must be written as -w "%%{http_code}". When typing directly in Command Prompt, a single % is fine.
Set Timeouts and Retries
On an unstable network, setting a wait time and a retry count keeps your process from hanging.
| Option | Description |
|---|---|
--max-time seconds | Upper limit for the whole operation |
--connect-timeout seconds | Upper limit for establishing the connection |
--retry count | Number of retries on transient errors |
curl -fsSL --connect-timeout 10 --max-time 60 --retry 3 -o setup.zip https://example.com/download/latest
Example: Check Whether a Download Succeeded
curl returns exit code 0 on success and a non-zero code on failure. Combined with -f, HTTP errors such as 404 are also treated as failures.
@echo off
setlocal
set "url=https://example.com/files/report.pdf"
set "dest=%USERPROFILE%\Downloads\report.pdf"
curl -fsSL --retry 3 -o "%dest%" "%url%"
if errorlevel 1 (
echo Download failed.
exit /b 1
)
echo Download completed: "%dest%"
endlocal
Exit codes are explained in
. With-f, curl returns exit code 22 on an HTTP error.
If a URL contains &, as in ?a=1&b=2, Command Prompt treats & as a command separator. Always enclose the URL in double quotes. In a batch file, a percent-encoded sequence such as %20 in the URL must be written as %%20.
-k skips HTTPS certificate verification, but then you cannot notice if the connection is eavesdropped on or tampered with. Use it only when you understand the risk, such as in an internal test environment, and normally leave it out.
Summary
| Goal | Example |
|---|---|
| Show content on screen | curl URL |
| Save with a specified name | curl -o name URL |
| Save with the URL’s name | curl -O URL |
| Follow redirects | curl -L URL |
| Check headers only | curl -I URL |
| Send JSON | curl -H "Content-Type: application/json" -d "..." URL |
| Get the status code | curl -s -o NUL -w "%{http_code}" URL |