有没有一种在Windows上安装cURL的方法,以便可以从命令提示符中运行cURL命令?
有没有一种在Windows上安装cURL的方法,以便可以从命令提示符中运行cURL命令?
https://superuser.com/questions/134685/run-curl-commands-from-windows-console/#483964
Git Bash
并开始使用 cURL :) - BRogers更新: Curl 现已包含在 Windows 中,无需通过 PowerShell 运行。
如果只需要查看或保存 GET 请求的结果,而不是实际需要 curl
可执行文件的人,可以直接使用 powershell
。从正常的命令提示符中,输入:
powershell -Command "(new-object net.webclient).DownloadString('http://example.com')"
虽然有点冗长,但与打字相似
curl http://example.com/
在更Unix风格的环境下。
有关net.webclient
的更多信息,请参见此处:WebClient Methods (System.Net)。
更新:我喜欢ImranHafeez在此答案中进一步扩展了此功能。然而,我更喜欢一个更简单的cmd脚本,也许可以创建一个包含以下内容的curl.cmd
文件:
@powershell -Command "(new-object net.webclient).DownloadString('%1')"
这可以像上面的类Unix示例一样被称为:
curl http://example.com/
powershell -Command "$wc=new-object net.webclient;$wc.Credentials=new-object System.Net.NetworkCredential(%user%,%pass%);$wc.DownloadString('%input%')"
,来源于 https://dev59.com/WXRB5IYBdhLWcg3wyqOo#509394 - Maxcurl https://www.example.com/mypage.php?action=hello
。在mypage.php脚本中,$_GET['action']
为空。 - Stephen R从2018年初开始,随着Windows 10 Insider Build 17063的推出,curl可以在cmd和powershell中使用。
在Windows中创建批处理文件,并使用cURL在Windows中愉快地使用 :)
@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
目前在Windows 10 build 17063及以上版本中,cURL
已默认安装。因此您无需下载,只需使用curl.exe
即可。
curl.exe
和 .crt
解压到 C:\Windows\System32
> curl https://api.stackexchange.com
p.s. 如果您想将可执行文件存储在另一个文件夹中,请检查您的路径 > echo %PATH%
如果您从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下载,适用于32位的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