有没有办法在Windows中安装cURL,以便从命令提示符运行cURL命令?


当前回答

更新:Curl现在包含在Windows中,不需要通过PowerShell运行它。

那些不需要curl可执行文件,而只是偶尔需要查看或保存GET请求结果的人,可以直接使用powershell。在普通的命令提示符中输入:

powershell -Command "(new-object net.webclient).DownloadString('http://example.com')"

虽然有点啰嗦,但与打字类似

curl http://example.com/

在更像unix的环境中。

更多关于网络的信息。webclient可以在这里使用:webclient Methods (System.Net)。

更新:我喜欢ImranHafeez在这个回答中更进一步的做法。我更喜欢一个简单的cmd脚本,但是,也许创建一个卷曲。包含这个的CMD文件:

@powershell -Command "(new-object net.webclient).DownloadString('%1')"

可以像上面的unix示例那样调用:

curl http://example.com/

其他回答

我已经使用MobaXterm,它运行curl命令正确。

在Windows命令提示符中,通过Git Bash运行curl

"C:\\Users\\sizu\\AppData\\Local\\Programs\\Git\\bin\\sh.exe" --login -i -c "curl https://www.google.com"

从https://cygwin.com/install.html下载cygwin的.exe文件(一个大型GNU和开源工具集合,其功能类似于Windows上的Linux发行版)。

运行.exe文件。

在安装时,您将在一个步骤中选择软件包。在选择包窗口——>中,将视图更改为“Not installed”并搜索curl。单击需要安装的包,单击包的“new”列—>,您可以看到版本号,然后单击下一步。(见下图)

安装完成后,单击cygwin打开窗口上的curl控制台并使用curl命令。

如果您下载它,它应该工作得很好 ——http://curl.haxx.se/dlwiz/?type=bin&os=Win64&flav=MinGW64——FOR 64BIT Win7/XP或from 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

简单的回答是:

(1)在这里下载curl二进制文件:https://curl.haxx.se/download.html(参见您的操作系统的二进制文件)。例子:

(2)创建文件夹“C:\curl”,然后解压所有文件

(3)编辑系统变量“Path”,最后添加“;C:\curl\bin”。完成了。

奥林匹克广播服务公司。:我见过一些人告诉添加“;C:\curl”,但这种方式不可能访问curl.exe。