从Windows控制台运行cURL命令

Dom*_*oSL 374 windows command-line curl

有没有办法在Windows中安装cURL才能从命令提示符运行cURL命令?

Gab*_*bák 448

如果您不是Cygwin,则可以使用本机Windows构建.有些在这里:卷曲下载向导.

  • 你可以安装`Git`并使用git bash.安装后内置.(见下面的答案). (7认同)

Ric*_*hez 164

首先,您需要下载cURL可执行文件.对于Windows 64位,下载它从这里和Windows支持32位的下载从这里 之后,保存curl.exe您的文件C:驱动器.

要使用它,只需打开command prompt并输入:

C:\curl http://someurl.com
Run Code Online (Sandbox Code Playgroud)

  • 哎呀,是的,这有帮助。好简单。感谢您发帖。 (2认同)

BRo*_*ers 137

如果你已经Git安装在Windows上,你可以使用GNU Bash它内置的....

https://superuser.com/questions/134685/run-curl-commands-from-windows-console/#483964

  • 这意味着您可以像运行OSX或Linux一样运行它,而无需使用特殊命令btw.刚开始`Git Bash`和cURL :) (3认同)
  • 这个答案需要更多的赞成.对于习惯使用mac终端或unix发行版的用户来说,这是一种方法. (2认同)

mat*_*tty 40

那些不需要curl可执行文件的人,而只需要一次又一次地查看或保存GET请求的结果,可以powershell直接使用.从正常的命令提示符处,键入:

powershell -Command "(new-object net.webclient).DownloadString('http://example.com')"
Run Code Online (Sandbox Code Playgroud)

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

curl http://example.com/
Run Code Online (Sandbox Code Playgroud)

在更加Unix的环境中.

有关更多信息,net.webclient请访问:WebClient方法(System.Net).

更新:我喜欢ImranHafeez在这个答案中更进了一步.我更喜欢更简单的cmd脚本,但是,可能会创建一个curl.cmd包含以下内容的文件:

@powershell -Command "(new-object net.webclient).DownloadString('%1')"
Run Code Online (Sandbox Code Playgroud)

可以像上面的Unix-ish示例一样调用它:

curl http://example.com/
Run Code Online (Sandbox Code Playgroud)


Hel*_*len 24

如果使用Chocolatey包管理器,则可以通过从命令行或从PowerShell运行此命令来安装cURL:

choco install curl
Run Code Online (Sandbox Code Playgroud)


Joj*_*ojo 13

自 2018 年初以来,随着 Windows 10 Insider build 17063,curl 可在 cmd 和 powershell 中使用。


小智 10

在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
Run Code Online (Sandbox Code Playgroud)


pro*_*365 9

目前在 Windows 10 build 17063 及更高版本中,cURL默认随 Windows 一起提供。那么你就不需要下载它并直接使用curl.exe


vla*_*ras 7

  1. 访问下载页面https://curl.haxx.se/download.html - 这太不可思议了
  2. 在列表中选择您的系统
  3. 不要忘记SSL支持,现在很明显,例如对于https
  4. 解压curl.exe.crtC:\Windows\System32
  5. 重启cmd
  6. 请享用 > curl https://api.stackexchange.com

ps如果您希望另一个文件夹存储可执行文件检查您的路径 > echo %PATH%


小智 6

如果你要从http://curl.haxx.se/dlwiz/?type=bin&os=Win64&flav=MinGW64 - 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
Run Code Online (Sandbox Code Playgroud)


Ish*_*era 6

从这里安装 git 命令行。当你在 Windows 中安装 git 时,你会自动获得curl。curl --version您可以使用如下命令检查已安装的curl 版本。

在此输入图像描述

这是一个示例curl 请求,它发送JSON 对象中的字符串并对其进行编码。

curl https://api.base62.io/encode \ --request POST \ --header "Content-Type: application/json" \ --data '{ "data": "Hello world!" }'

在此输入图像描述


Par*_*ban 5

为Windows安装Git,然后使用git bash运行curl命令。