【问题标题】:CMD/Powershell: Commands not working with cURL. Cygwin worksCMD/Powershell:命令不适用于 cURL。赛格温作品
【发布时间】:2014-01-14 04:12:48
【问题描述】:

我正在尝试让本教程在 CMD 和 Windows Powershell (Windows 7 64) 中工作:http://www.elasticsearchtutorial.com/elasticsearch-in-5-minutes.html

第一个命令在 CMD 中已经不起作用:

curl -XPUT 'http://localhost:9200/blog/user/dilbert' -d '{ "name" : "Dilbert Brown" }'

我收到以下错误消息:

curl: (1) Protocol 'http not supported or disabled in libcurl
curl: (6) Could not resolve host: name
curl: (7) Failed to connect to  port 80: Connection refused
curl: (6) Could not resolve host: Dilbert Brown
curl: (3) [globbing] unmatched close brace/bracket in column 1

在 Windows Powershell 中我得到:

{"error":"MapperParsingException[failed to parse]; nested: JsonParseException[Unrecognized token 'Dilbert': was expecting ('true', 'false' or 'null')\n at [Source: [B@132b73b; line: 1, column: 33]]; ","status":400}curl: (3) [globbing] unmatched close brace/bracket in column 7

相同的命令在 Cygwin 中没有任何问题。我必须如何编写命令才能使其在 CMD 和 Windows Powershell 中工作?

【问题讨论】:

    标签: windows powershell curl cmd cygwin


    【解决方案1】:

    在 PowerShell 中,从解析的角度来看,该命令被正确调用。

    在 cmd.exe 中,单引号无效。您需要使用双引号将值括起来。

    curl -XPUT "http://localhost:9200/blog/user/dilbert" -d "{ \"name\" : \"Dilbert Brown\" }"
    

    【讨论】:

    • 谢谢!我现在正在使用 Chrome 插件“Sense”。它使使用 ElasticSearch 比在命令行中使用 cURL 更容易。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 2021-05-02
    • 1970-01-01
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多