有没有办法在 Windows 中安装 cURL 以便从命令提示符运行 cURL 命令?
如果您在 Windows 上安装了 Git
,则可以使用 GNU Bash
...。它是内置的。
https://superuser.com/questions/134685/run-curl-commands-from-windows-console/#483964
Git Bash
和 cURL 即可:)
那些并不真正需要 curl
可执行文件,而只是需要不时查看或保存 GET 请求的结果的人,可以直接使用 powershell
。在正常的命令提示符下,键入:
powershell -Command "(new-object net.webclient).DownloadString('http://example.com')"
这虽然有点罗嗦,但类似于打字
curl http://example.com/
在更 Unix-ish 的环境中。
有关 net.webclient
的更多信息,请参见此处:WebClient Methods (System.Net)。
更新:我喜欢 ImranHafeez 在 this answer 中如何更进一步。不过,我更喜欢更简单的 cmd 脚本,可能会创建一个包含以下内容的 curl.cmd
文件:
@powershell -Command "(new-object net.webclient).DownloadString('%1')"
可以像上面的 Unix-ish 示例一样调用它:
curl http://example.com/
powershell -Command "$wc=new-object net.webclient;$wc.Credentials=new-object System.Net.NetworkCredential(%user%,%pass%);$wc.DownloadString('%input%')"
curl https://www.example.com/mypage.php?action=hello
。在 mypage.php 脚本中,$_GET['action']
为空
在 windows 中创建批处理文件并在 windows 中使用 cURL :)
@echo off
echo You are about to use windows cURL, Enter your url after curl command below:
set /p input="curl "
cls
echo %input%
powershell -Command "(new-object net.webclient).DownloadString('%input%')"
pause
自 2018 年初以来,Windows 10 Insider build 17063 curl 在 cmd 和 powershell 中可用。
访问下载页面 https://curl.haxx.se/download.html - 太棒了 在列表中选择您的系统 不要忘记 SSL 支持,现在很明显,例如 https 将 curl.exe 和 .crt 解包到 C:\Windows \System32 重启 cmd 享受 > curl https://api.stackexchange.com
ps 如果您想要另一个文件夹来存储可执行文件,请检查您的路径 > echo %PATH%
如果您从 --http://curl.haxx.se/dlwiz/?type=bin&os=Win64&flav=MinGW64 -- FOR 64BIT Win7/XP 或从 http://curl.haxx.se/dlwiz/?type=bin&os=Win32&flav=-&ver=2000%2FXP --- FOR 32BIT Win7/XP 下载它,它应该可以正常工作,只需将文件解压缩到 c:/Windows 并从 cmd 运行
C:\Users\WaQas>curl -v google.com
* About to connect() to google.com port 80 (#0)
* Trying 173.194.35.105...
* connected
* Connected to google.com (173.194.35.105) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.28.1
> Host: google.com
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 301 Moved Permanently
< Location: http://www.google.com/
< Content-Type: text/html; charset=UTF-8
< Date: Tue, 05 Feb 2013 00:50:57 GMT
< Expires: Thu, 07 Mar 2013 00:50:57 GMT
< Cache-Control: public, max-age=2592000
< Server: gws
< Content-Length: 219
< X-XSS-Protection: 1; mode=block
< X-Frame-Options: SAMEORIGIN
< X-Cache: MISS from LHR-CacheMARA3
< X-Cache-Lookup: HIT from LHR-CacheMARA3:64003
< Connection: close
<
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
* Closing connection #0
安装 Git for windows 然后使用 git bash 运行 curl 命令。
目前在 Windows 10 build 17063 及更高版本中,cURL
默认随 Windows 提供。然后您不需要下载它,只需使用 curl.exe
。
我能够使用此 site 在我的 Windows 机器上轻松下载和安装 curl。整个过程用了 30 秒。我使用的是 Windows 7(具有管理员权限),因此我从 http://curl.haxx.se/download.html 下载了 curl-7.37.0-win64.msi。
另外,安装 curl 后不要忘记重新启动控制台/终端,否则您将收到相同的错误消息。
从 here 安装 git 命令行。当你在 windows 中安装 git 时,你会自动得到 curl。您可以像这样使用 curl --version
检查已安装的 curl 版本。
https://i.stack.imgur.com/KBfkk.jpg
这是一个示例 curl 请求,它在 JSON 对象中发送一个字符串并对其进行编码。
curl https://api.base62.io/encode \ --request POST \ --header "Content-Type: application/json" \ --data '{ "data": "Hello world!" }'
https://i.stack.imgur.com/soMca.jpg
我还发现,如果我将 cygwin bin 放在我的 windows 路径上,我可以从 windows 命令行运行 curl。它还可以让您访问诸如 ls 和 grep 之类的东西
假设您是游戏新手或由于安全限制无法安装软件,您可以使用 Scoop 安装 curl。从 powershell 或命令窗口运行以下命令。请注意,这假设您拥有 Powershell v3.0+。
这里的另一个很酷的优势是,它只为当前用户安装软件。
设置执行异常 Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser 安装 Scoop iex(new-object net.webclient).downloadstring('https://get.scoop.sh') 安装 curl。您可能会看到有关缺少哈希的警告,但您应该会看到一条最终消息,表明 cURL 已成功安装 scoop install curl 测试 curl curl -L https://get.scoop.sh 的安装
iex (new-object net.webclient).downloadstring('https://a.url.here')
下载和运行 PS 脚本正是我所需要的。
在 Windows 命令提示符下,通过 Git Bash 运行 curl
"C:\\Users\\sizu\\AppData\\Local\\Programs\\Git\\bin\\sh.exe" --login -i -c "curl https://www.google.com"
转到 curl 下载向导 选择 curl 可执行文件 选择 Win32 或 Win64 然后根据您的要求为其选择包(例如通用/cygwin)然后您必须选择版本。您可以选择未指定。这将直接带您到下载链接,单击该链接会弹出下载 zip 文件的窗口。解压缩 zip 以获取可执行文件。在你的环境变量中添加这个文件夹,你就完成了。然后,您可以从 cmd 执行 curl 命令。
从 https://cygwin.com/install.html 下载 .exe 文件,用于 cygwin(大量 GNU 和开源工具,提供类似于 Windows 上的 Linux 发行版的功能)。
运行 .exe 文件。
https://i.stack.imgur.com/BqIzh.png
完成安装后,单击 cygwin 在 Windows 上打开 curl 控制台并处理 curl 命令。
我可能有点晚了,但我能够在 Windows 10 的 cmd 处解决我的 curl 问题。
我从以下视频教程中获得了帮助 https://www.youtube.com/watch?v=qlTVMuONazs
这里有一些解释
第 1 步:转到 https://curl.haxx.se/download.html
第 2 步:搜索“Win64 - Generic”并下载“Darren Owen”的“Win64 x86_64 7zip”
第三步:解压下载文件并安装证书“ca-bundle.crt”不要碰curl.exe
第 4 步:在 Windows 中转到“控制面板”->“系统”->“高级系统设置”第 5 步:单击环境变量
第 6 步:在系统变量中单击“路径”并粘贴文件夹的路径,在我的情况下它是“C:\curl\curl_7_53_1_openssl_nghttp2_x64”
你完成了。
不要忘记重新启动系统一次
最简单的答案:
(1) 在此处下载 curl 二进制文件:https://curl.haxx.se/download.html(请参阅适用于您的操作系统的二进制文件)。例子:
https://i.stack.imgur.com/tzdRk.png
(2) 创建一个文件夹“C:\curl”然后解压到那里
https://i.stack.imgur.com/j6q6o.png
(3) 通过在末尾添加“;C:\curl\bin”来编辑名为“Path”的系统变量。完成的。
https://i.stack.imgur.com/OCTwz.png
Obs.:我见过一些人告诉添加“;C:\curl”,但这样就无法访问 curl.exe。
对于任何寻求快速解决方案的人,在标准安装 cygwin 后发现 curl 在 win 10 x64 平台上不起作用:
下载 this 已停用的存储库,将其解压缩并运行:
git-cmd.bat
像魅力一样工作。我认为它具有 curl 的预安装选项。
我使用了 MobaXterm
,它正确运行了 curl
命令。
不定期副业成功案例分享
Git
并使用 git bash。安装后内置。 (见下面的答案)。