我正在测试一些 nodejs 服务器代码,并想使用 curl 命令从 windows power shell 测试 url。这里需要注意一些事情: 1. 我的系统中安装了 mingw 和 git bash,curl 在普通命令提示符和 git bash 提示符下工作正常。 2. 此外,我还从curl official web site 下载了最新版本的cURL。并将bin目录的路径添加到系统的PATH变量中。
不过好像对power shell不好。但是,无论系统中是否存在其他 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>
但是当我在普通命令提示符下尝试时,它工作正常:
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>
当我从 git bash 尝试时,我也得到相同的输出。
我的问题是,如果我希望一切都在 Windows Power Shell 中也能顺利运行,我需要做什么?我在网上做了一些搜索,但找不到太多有用的资源。此外,我以前没有任何使用 Windows PowerShell 的经验。通常使用linux作为开发环境。
最佳答案
看起来您已经将 curl
作为 Ivoke-WebRequest
的别名:
Invoke-WebRequest : A parameter cannot be found that matches parameter name 'X'.
尝试运行 remove-item alias:\curl
看看现在是否调用了正确的 curl。或者,尝试指定绝对路径,即 c:\curl\curl.exe ...
。
关于windows - powershell windows 8.1 中的 cURL : "A drive with the name ' localhost' does not exist",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27719275/