从 Windows 控制台运行 cURL 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2710748/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:17:32  来源:igfitidea点击:

Run cURL commands from Windows console

windowscommand-linecurl

提问by DomingoSL

Is there a way to install cURL in Windows in order to run cURL commands from the command prompt?

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

回答by Gabriel ??erbák

If you are not into Cygwin, you can use native Windows builds. Some are here: curl Download Wizard.

如果您不喜欢Cygwin,则可以使用本机 Windows 构建。一些在这里:curl 下载向导

回答by Ricardo Sanchez

First you need to download the cURL executable. For Windows 64bit, download it from hereand for Windows 32bit download from hereAfter that, save the curl.exefile on your C:drive.

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

To use it, just open the command promptand type in:

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

C:\curl http://someurl.com

回答by BRogers

If you have Gitinstalled on windows you can use the GNU Bash.... it's built in.

如果您已Git安装在 Windows 上,则可以使用GNU Bash.... 它是内置的。

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

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

回答by matty

Folks that don't literally need the curlexecutable, but rather just need to e.g. see or save the results of a GET request now and again, can use powershelldirectly. From a normal command prompt, type:

真正不需要curl可执行文件,而只是需要时不时地查看或保存 GET 请求的结果的人可以powershell直接使用。在正常的命令提示符下,键入:

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

which, while a bit wordy, is similar to typing

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

curl http://example.com/

in a more Unix-ish environment.

在更 Unix 的环境中。

More information about net.webclientis available here: WebClient Methods (System.Net).

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

UPDATE: I like how ImranHafeez took this one step further in this answer. I'd prefer a simpler cmd-script however, maybe creating a curl.cmdfile containing this:

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

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

which could be called just like the Unix-ish example above:

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

curl http://example.com/

回答by Helen

If you use the Chocolateypackage manager, you can install cURLby running this command from the command line or from PowerShell:

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

choco install curl

回答by ImranHafeez

Create batch file in windows and enjoy with cURL in windows :)

在 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

回答by vladkras

  1. Visit download page https://curl.haxx.se/download.html- it's incredible
  2. Choose your sytem in list
  3. Don't forget SSL support, it's obvious now, e.g. for https
  4. Unpack curl.exeand .crtto C:\Windows\System32
  5. Restart cmd
  6. Enjoy > curl https://api.stackexchange.com
  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

p.s. If you want another folder to store executable check your paths > echo %PATH%

ps 如果你想要另一个文件夹来存储可执行文件,请检查你的路径 > echo %PATH%

回答by WaQas

it should work perfectly fine if you would download it from --http://curl.haxx.se/dlwiz/?type=bin&os=Win64&flav=MinGW64-- FOR 64BIT Win7/XP OR from http://curl.haxx.se/dlwiz/?type=bin&os=Win32&flav=-&ver=2000%2FXP--- FOR 32BIT Win7/XP just extract the files to c:/Windows and run it from cmd

它应该完全正常工作如果你想从下载- http://curl.haxx.se/dlwiz/?type=bin&os=Win64&flav=MinGW64-对于64位的Win7 / XP或从HTTP://curl.haxx。 se/dlwiz/?type=bin&os=Win32&flav=-&ver=2000%2FXP--- 对于 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

回答by Parthiban

Install Git for windows Then use git bash to run curl commands.

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

回答by Scott Izu

From Windows Command Prompt, run curl through Git Bash

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

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