PowerShell 里 curl 和 curl.exe 的区别(别名陷阱)
Windows PowerShell 中 curl 和 wget 其实是 Invoke-WebRequest 的别名,真正的 curl 要写成 curl.exe。
想运行真正的 curl 请使用 curl.exe(带 .exe 后缀);PowerShell 5.1 里直接输入 curl 执行的是 Invoke-WebRequest。
01命令
命令
$ curl.exe -I https://example.com
Get-Alias curl
Get-Command curl.exe | Select-Object Source02作用说明
Windows PowerShell 5.1 把 curl 和 wget 定义成了 Invoke-WebRequest 的别名,所以照着网上教程粘贴 curl 命令会报"找不到参数"或卡在交互提示。真正的 curl.exe(libcurl 官方构建)从 Windows 10 1803 起就自带在 System32 里,加上 .exe 后缀即可绕过别名直接调用。PowerShell 7 删除了这些别名,所以同样的命令在那里能正常工作——为保险起见,脚本里应始终写 curl.exe。
03风险
!注意: 不要通过删掉内置别名来"修复"这个问题,其他工具可能依赖它;统一使用 curl.exe 写法最稳妥。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- Invoke-WebRequest - SS64依据: Notes that curl is an alias for Invoke-WebRequest in Windows PowerShell and that curl.exe is the separate native binary.
- Invoke-WebRequest依据: Invoke-WebRequest is the cmdlet behind PowerShell's curl alias; it uses different syntax than curl.exe.
最后验证: 2026-09-18 · 分类: 开发者