电源外壳程序窗口8.1中的cURL:"名称为'localhost'的驱动器不存在"

Zob*_*san 6 windows command-line curl path

我正在测试一些nodejs服务器代码,并希望使用curl命令测试来自windows power shell的url.这里需要注意的一些事项:1.我在系统中安装了mingw和git bash,并且curl在正常命令提示符和git bash提示符下工作正常.2.此外,我从curl官方网站下载了最新版本的cURL ,并将bin目录的路径添加到系统的PATH变量中.

但似乎它对电源外壳没有好处.但是,无论系统中是否存在其他cURL程序或git bash,powershell仍会识别cURL命令.但它没有像我预期的那样工作,例如我尝试了以下命令:

Windows PowerShell
Copyright (C) 2013 Microsoft Corporation. All rights reserved.

PS C:\Users\Zobayer Hasan> curl -X GET -i localhost:8080
Invoke-WebRequest : A parameter cannot be found that matches parameter name 'X'.
At line:1 char:6
+ curl -X GET -i localhost:8080
+      ~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

PS C:\Users\Zobayer Hasan> curl GET -i localhost:8080
curl : Cannot find drive. A drive with the name 'localhost' does not exist.
At line:1 char:1
+ curl GET -i localhost:8080
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (localhost:String) [Invoke-WebRequest], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

PS C:\Users\Zobayer Hasan> curl GET -i http://localhost:8080
curl : Cannot find drive. A drive with the name 'http' does not exist.
At line:1 char:1
+ curl GET -i http://localhost:8080
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (http:String) [Invoke-WebRequest], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

PS C:\Users\Zobayer Hasan>
Run Code Online (Sandbox Code Playgroud)

但是当我在正常的命令提示符下尝试它时,它工作正常:

C:\Users\Zobayer Hasan>curl -X GET -i localhost:8080
HTTP/1.1 200 OK
Date: Wed, 31 Dec 2014 09:35:31 GMT
Connection: keep-alive
Transfer-Encoding: chunked

Server connection was called
C:\Users\Zobayer Hasan>
Run Code Online (Sandbox Code Playgroud)

当我从git bash尝试它时,我也得到相同的输出.

我的问题是,如果我想在Windows power shell中运行顺畅,我还需要做什么?我在网上做了一些搜索,找不到很多有用的资源.此外,我没有任何Windows powershell的经验.通常使用linux作为开发环境.

ant*_*ous 16

看起来您已经curl将别名作为别名Ivoke-WebRequest:

Invoke-WebRequest:找不到与参数名称"X"匹配的参数.

尝试运行remove-item alias:\curl,看看你现在是否正在调用正确的卷曲.或者,尝试指定绝对路径,即c:\curl\curl.exe ....


小智 5

由于我更新到 PowerShell 4.0,因此创建了一个别名以指向名为 curl 的 Invoke-WebRequest,所以我所做的是将我自己的别名添加到我想要使用的 curl.exe 可执行文件中:

set-alias mcurl "C:\cygwin\bin\curl.exe"
Run Code Online (Sandbox Code Playgroud)

Powershell 4.0

Get-Alias curl

CommandType 名称 ModuleName ----------- ---- ---------- 别名 curl -> Invoke-WebRequest

我的新别名:

获取别名 mcurl

CommandType 名称 ModuleName ----------- ---- ---------- 别名 mcurl -> curl.exe