PowerShell 里 curl 和 curl.exe 的区别(别名陷阱)

Windows PowerShell 中 curl 和 wget 其实是 Invoke-WebRequest 的别名,真正的 curl 要写成 curl.exe。

Windowscurl 请求别名开发PowerShell低风险
想运行真正的 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 Source

02作用说明

Windows PowerShell 5.1 把 curl 和 wget 定义成了 Invoke-WebRequest 的别名,所以照着网上教程粘贴 curl 命令会报"找不到参数"或卡在交互提示。真正的 curl.exe(libcurl 官方构建)从 Windows 10 1803 起就自带在 System32 里,加上 .exe 后缀即可绕过别名直接调用。PowerShell 7 删除了这些别名,所以同样的命令在那里能正常工作——为保险起见,脚本里应始终写 curl.exe。

03风险

风险低风险
使用条件Windows 10 1803+ ships curl.exe in System32; on older builds install it separately.
!注意: 不要通过删掉内置别名来"修复"这个问题,其他工具可能依赖它;统一使用 curl.exe 写法最稳妥。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • Invoke-WebRequest - SS64
    SS64 · technical · 2026-09-17
    依据: Notes that curl is an alias for Invoke-WebRequest in Windows PowerShell and that curl.exe is the separate native binary.
  • Invoke-WebRequest
    Microsoft Learn · vendor-doc · 2026-09-17
    依据: Invoke-WebRequest is the cmdlet behind PowerShell's curl alias; it uses different syntax than curl.exe.

最后验证: 2026-09-18 · 分类: 开发者

06相关方案