Power Shell windows 8.1 中的 cURL:"一个名为 'localhost' 的驱动器不存在" [英] cURL in power shell windows 8.1: "A drive with the name 'localhost' does not exist"

查看:48
本文介绍了Power Shell windows 8.1 中的 cURL:"一个名为 'localhost' 的驱动器不存在"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was testing some nodejs server code and wanted to test the urls from windows power shell using the curl command. Some things to note here: 1. I have mingw and git bash installed in my system, and curl works fine from normal command prompt and git bash prompt. 2. Additionally I have downloaded the latest version of cURL from curl official web site and added the path of bin directory to the system's PATH variable.

不过好像对power shell没有好处.但是,无论系统中是否存在其他 cURL 程序或 git bash,powershell 仍然可以识别 cURL 命令.但它并没有像我预期的那样工作,例如我尝试了以下命令和:

But it seems like it is no good for power shell. However, powershell still recognizes cURL command regardless of additional cURL program or git bash present in the system or not. But it does not work as I expected it to be, for example I have tried the following command and:

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>

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

But when I try it in normal command prompt, it works fine:

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 尝试它时,我也得到了相同的输出.

I also get the same output when I try it from git bash.

我的问题是,如果我也希望 Windows Power Shell 中的一切都顺利运行,我需要做什么?我在网上做了一些搜索,找不到太多有用的资源.此外,我之前没有任何使用 windows powershell 的经验.通常使用linux作为开发环境.

My question here is what do I need to do if I want everything to run smooth in windows power shell as well? I have done a little bit of searching on the net, and could not find much helpful resources. Also I have not any prior experience with windows powershell. Usually use linux as development environment.

推荐答案

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

It looks like you already have curl as an alias to Ivoke-WebRequest:

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

Invoke-WebRequest : A parameter cannot be found that matches parameter name 'X'.

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

Try running remove-item alias:\curl and see if you now get the right curl being invoked. Alternatively, try by specifying the absolute path, i.e. c:\curl\curl.exe ....

这篇关于Power Shell windows 8.1 中的 cURL:"一个名为 'localhost' 的驱动器不存在"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆