安装最新的 PowerShell,了解新功能和改进!https://aka.ms/PSWindows
PS C:\Users\Administrator> # 以管理员身份打开 PowerShell >> $curlPath = "E:\curl-8.15.0_4-win64-mingw\bin" >> $currentPath = [Environment]::GetEnvironmentVariable("Path", "Machine") >> >> # 检查是否已添加
>> if (-not $currentPath.Contains($curlPath)) {
>> # 添加到系统PATH
>> [Environment]::SetEnvironmentVariable(
>> "Path",
>> "$currentPath;$curlPath",
>> "Machine"
>> )
>>
>> # 刷新当前会话的PATH
>> $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine")
>>
>> Write-Host "✅ curl 已添加到系统PATH" -ForegroundColor Green
>> } else {
>> Write-Host "ℹ️ curl 已在系统PATH中" -ForegroundColor Yellow
>> }
>>
✅ curl 已添加到系统PATH
PS C:\Users\Administrator> # 检查curl版本
>> curl --version
>>
>> # 预期输出应包含:
>> # curl 8.15.0 (x86_64-pc-win32) ...
>> # Release-Date: 2025-07-16
>> # Protocols: dict file ftp ftps gopher gophers http https ...
>>
curl : 未能解析此远程名称: '--version'
所在位置 行:2 字符: 1 + curl --version + ~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest],WebExce ption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
PS C:\Users\Administrator> # 测试HTTP请求
>> curl https://example.com
>>
>> # 测试HTTPS请求
>> curl https://jsonplaceholder.typicode.com/todos/1
>>
>> # 测试文件下载
>> curl -O https://example.com/index.html
>>
StatusCode : 200
StatusDescription : OK
Content : <!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" conten...
RawContent : HTTP/1.1 200 OK
Alt-Svc: h3=":443"; ma=93600,h3-29=":443"; ma=93600
Connection: keep-alive
Accept-Ranges: bytes
Content-Length: 1256
Cache-Control: max-age=3131
Content-Type: text/html
Date: Tu...
Forms : {}
Headers : {[Alt-Svc, h3=":443"; ma=93600,h3-29=":443"; ma=93600], [Connection, keep-alive], [Accept-Ranges, b
ytes], [Content-Length, 1256]...}
Images : {}
InputFields : {}
Links : {@{innerHTML=More information...; innerText=More information...; outerHTML=<A href="https://www.ian
a.org/domains/example">More information...</A>; outerText=More information...; tagName=A; href=http
s://www.iana.org/domains/example}}
ParsedHtml : System.__ComObject
RawContentLength : 1256
StatusCode : 200
StatusDescription : OK
Content : {
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}
RawContent : HTTP/1.1 200 OK
Connection: keep-alive
CF-RAY: 96df6aeb3ca7a3d1-SEA
access-control-allow-credentials: true
nel: {"report_to":"heroku-nel","response_headers":["Via"],"max_age":3600,"success_fractio...
Forms : {}
Headers : {[Connection, keep-alive], [CF-RAY, 96df6aeb3ca7a3d1-SEA], [access-control-allow-credentials, true]
, [nel, {"report_to":"heroku-nel","response_headers":["Via"],"max_age":3600,"success_fraction":0.01
,"failure_fraction":0.1}]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : System.__ComObject
RawContentLength : 83
位于命令管道位置 1 的 cmdlet Invoke-WebRequest
请为以下参数提供值:
Uri: # 使用完整路径调用真正的 curl
curl : 无效的 URI: 未能分析主机名。
所在位置 行:8 字符: 1
+ curl -O https://example.com/index.html
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-WebRequest], UriFormatException
+ FullyQualifiedErrorId : System.UriFormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
PS C:\Users\Administrator> E:\curl-8.15.0_4-win64-mingw\bin\curl.exe --version
curl 8.15.0 (x86_64-w64-mingw32) libcurl/8.15.0 LibreSSL/4.1.0 zlib/1.3.1.zlib-ng brotli/1.1.0 zstd/1.5.7 WinIDN libpsl/0.21.5 libssh2/1.11.1 nghttp2/1.66.0 ngtcp2/1.14.0 nghttp3/1.11.0
Release-Date: 2025-07-16
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns ldap ldaps mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp ws wss
Features: alt-svc AsynchDNS brotli CAcert HSTS HTTP2 HTTP3 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM PSL SPNEGO SSL SSLS-EXPORT SSPI threadsafe UnixSockets zstd
PS C:\Users\Administrator>
PS C:\Users\Administrator> # 测试真正的 curl
PS C:\Users\Administrator> E:\curl-8.15.0_4-win64-mingw\bin\curl.exe https://example.com
<!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
div {
width: 600px;
margin: 5em auto;
padding: 2em;
background-color: #fdfdff;
border-radius: 0.5em;
box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
@media (max-width: 700px) {
div {
margin: 0 auto;
width: auto;
}
}
</style>
</head>
<body>
<div>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples in documents. You may use this
domain in literature without prior coordination or asking for permission.</p>
<p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>
PS C:\Users\Administrator> # 创建永久别名(添加到 PowerShell 配置文件)
>> $profileContent = @"
>> # 添加 curl 别名
>> function Invoke-Curl {
>> & "E:\curl-8.15.0_4-win64-mingw\bin\curl.exe" @args
>> }
>> Set-Alias -Name realcurl -Value Invoke-Curl
>> "@
>>
>> # 创建配置文件(如果不存在)
>> if (-not (Test-Path $PROFILE)) {
>> New-Item -Path $PROFILE -ItemType File -Force
>> }
>>
>> # 添加内容到配置文件
>> $profileContent | Add-Content -Path $PROFILE
>>
>> # 立即加载配置文件
>> . $PROFILE
>>
>> # 现在可以使用 realcurl 命令
>> realcurl --version
>>
目录: C:\Users\Administrator\Documents\WindowsPowerShell
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2025/8/12 18:52 0 Microsoft.PowerShell_profile.ps1
curl 8.15.0 (x86_64-w64-mingw32) libcurl/8.15.0 LibreSSL/4.1.0 zlib/1.3.1.zlib-ng brotli/1.1.0 zstd/1.5.7 WinIDN libpsl/0.21.5 libssh2/1.11.1 nghttp2/1.66.0 ngtcp2/1.14.0 nghttp3/1.11.0
Release-Date: 2025-07-16
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns ldap ldaps mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp ws wss
Features: alt-svc AsynchDNS brotli CAcert HSTS HTTP2 HTTP3 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM PSL SPNEGO SSL SSLS-EXPORT SSPI threadsafe UnixSockets zstd
PS C:\Users\Administrator> # 临时删除 PowerShell 的 curl 别名
>> Remove-Item Alias:curl -ErrorAction SilentlyContinue
>>
>> # 现在可以直接使用 curl
>> curl --version
>>
Warning: C:\Users\Administrator\.curlrc:2: warning: '--compressed' the
Warning: installed libcurl version doesn't support this
curl 8.4.0 (Windows) libcurl/8.4.0 Schannel WinIDN
Release-Date: 2023-10-11
Protocols: dict file ftp ftps http https imap imaps pop3 pop3s smtp smtps telnet tftp
Features: AsynchDNS HSTS HTTPS-proxy IDN IPv6 Kerberos Largefile NTLM SPNEGO SSL SSPI threadsafe Unicode UnixSockets
PS C:\Users\Administrator> # 验证真正的 curl 安装
>> & "E:\curl-8.15.0_4-win64-mingw\bin\curl.exe" --version
>>
>> # 预期输出:
>> # curl 8.15.0 (x86_64-pc-win32) ...
>> # Release-Date: 2025-07-16
>> # Protocols: dict file ftp ftps gopher gophers http https ...
>>
curl 8.15.0 (x86_64-w64-mingw32) libcurl/8.15.0 LibreSSL/4.1.0 zlib/1.3.1.zlib-ng brotli/1.1.0 zstd/1.5.7 WinIDN libpsl/0.21.5 libssh2/1.11.1 nghttp2/1.66.0 ngtcp2/1.14.0 nghttp3/1.11.0
Release-Date: 2025-07-16
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns ldap ldaps mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp ws wss
Features: alt-svc AsynchDNS brotli CAcert HSTS HTTP2 HTTP3 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM PSL SPNEGO SSL SSLS-EXPORT SSPI threadsafe UnixSockets zstd
PS C:\Users\Administrator> # 使用真正的 curl 下载文件
>> & "E:\curl-8.15.0_4-win64-mingw\bin\curl.exe" -O https://example.com/index.html
>>
>> # 或者使用别名(如果已设置)
>> realcurl -O https://example.com/index.html
最新发布