Curl for Windows Example

Windows has shipped a real curl since 2018. What trips people up is not the program but the shells around it: PowerShell hijacks the name, and neither shell quotes the way the bash examples in every API reference assume.

Last updated . How this page is checked.

The command

curl.exe -H "Content-Type: application/json" -d "{\"name\":\"Ada\"}" https://httpbin.org/post

What the flags do

FlagWhat it does
curl.exeAlways type the .exe in PowerShell to get the real curl.
-d @file.jsonRead the body from a file and avoid quoting altogether.
-o NULDiscard output. The Windows equivalent of /dev/null.
--ssl-no-revokeSkip certificate revocation checks, which fail behind some corporate proxies.

curl versus curl.exe

Windows 10 version 1803 and later include curl.exe in System32. In cmd.exe, typing curl runs it. In Windows PowerShell 5.1, curl is an alias for the unrelated Invoke-WebRequest cmdlet, which understands none of curl's flags, hence errors such as "Cannot bind parameter 'Headers'". Typing curl.exe bypasses the alias. PowerShell 7 removed the alias, so there curl means curl.

Get-Command curl          # shows Alias -> Invoke-WebRequest on PowerShell 5.1
curl.exe --version        # the real thing

Quoting in cmd.exe

cmd does not treat single quotes as quotes. A JSON body wrapped in single quotes arrives at curl in pieces. Use double quotes around the argument and escape each inner double quote with a backslash. Line continuation is a caret, not a backslash.

curl -X POST https://httpbin.org/post ^
  -H "Content-Type: application/json" ^
  -d "{\"name\":\"Ada\",\"role\":\"admin\"}"

Quoting in PowerShell

PowerShell does have single-quoted strings, but Windows PowerShell 5.1 strips inner double quotes when it hands arguments to a native program, so JSON still needs its quotes escaped with backslashes. PowerShell 7.3 and later pass them through unchanged. Line continuation is a backtick. Because the rules depend on the version, the dependable approach is a file.

# works in every PowerShell version
'{"name":"Ada","role":"admin"}' | Set-Content body.json
curl.exe -H "Content-Type: application/json" -d "@body.json" https://httpbin.org/post

# Windows PowerShell 5.1 inline
curl.exe -H "Content-Type: application/json" -d '{\"name\":\"Ada\"}' https://httpbin.org/post

Common mistakes

  • The built-in curl uses Schannel, Windows' own TLS stack, so it trusts the Windows certificate store and ignores a --cacert bundle in some configurations.
  • @ is special in PowerShell. Quote arguments such as "@body.json" and "file=@photo.png".
  • Git Bash and WSL behave like Linux. There the bash examples work as written, including single quotes.

Related curl examples

More under Reference

References

These links leave api-tester.com, which is independent of the projects they point to.

FAQ

Is curl installed on Windows?

Yes. Windows 10 version 1803 and later, and Windows 11, include curl.exe. Run curl.exe --version to confirm.

Why does curl not work in PowerShell?

In Windows PowerShell 5.1, curl is an alias for Invoke-WebRequest, which does not accept curl options. Run curl.exe instead to use the real curl.

How do I send JSON with curl on Windows?

In cmd, wrap the JSON in double quotes and escape inner quotes with backslashes. The most reliable method in any shell is to put the JSON in a file and send it with -d @file.json.