curl - Download and Send Data over HTTP

Maintained on

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
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>curl https://example.com
<!doctype html>
<html>
…
C:\users\user>
Check whether curl is available

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 PowerShell, type curl.exe

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

to check where that is.

Existing files are overwritten without confirmation

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.

OptionDescription
-sHides the progress meter and error messages (silent)
-SUsed with -s, shows a message only when an error occurs
-fOn 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
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>curl -I https://example.com
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Content-Length: 1256
…
C:\users\user>
おすすめ書籍※ 広告を含む場合があります
中小企業経営者のためのRPA入門 RPA導入を成功させる方法

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

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

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

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

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

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかる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
`-X POST` can be omitted

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.

Pass JSON containing non-ASCII text as a file

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

for details.

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
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>curl -s -o NUL -w "%{http_code}" https://example.com
200
C:\users\user>

-o NUL discards the body (NUL is a special device name that discards anything written to it).

Double the % in batch files

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.

OptionDescription
--max-time secondsUpper limit for the whole operation
--connect-timeout secondsUpper limit for establishing the connection
--retry countNumber 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.

Quote URLs that contain &

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.

About -k, which ignores certificate errors

-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

GoalExample
Show content on screencurl URL
Save with a specified namecurl -o name URL
Save with the URL’s namecurl -O URL
Follow redirectscurl -L URL
Check headers onlycurl -I URL
Send JSONcurl -H "Content-Type: application/json" -d "..." URL
Get the status codecurl -s -o NUL -w "%{http_code}" URL

Practice Questions

Practice Problem

Which option should you add to follow a redirecting URL, such as a short URL, and fetch its destination?

回答がサーバーに送信されることはありません
Practice Problem

Which option makes curl exit with an error instead of saving the error page on an HTTP error response such as 404?

回答がサーバーに送信されることはありません
#Command Prompt #Batch File #Command Line #Command #curl #Network #Download