【问题标题】:Windows: curl with json data on the command lineWindows:在命令行上使用 json 数据卷曲
【发布时间】:2015-04-23 06:47:00
【问题描述】:

我在 Windows 提示符下运行以下命令:

curl -XPUT http://127.0.0.1:9200/test-index/test-type/_mapping?pretty=true -d '{"test-type": {"properties": {"name": {"index": "analyzed", "term_vector": "with_positions_offsets", "boost": 1.0, "store": "yes", "type": "string"}}}}'

我收到以下错误:

{
  "error" : "ElasticsearchParseException[Failed to parse content to map]; nested: JsonParseException[Unexpected character (''' (code 39)): expected a
valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.elasticsearch.common.compress.lzf.LZFCompressedStreamInput@45
4ed1d2; line: 1, column: 2]]; ",
  "status" : 400
}

我搜索了解决方案并找到了替代方法,例如将 json 数据放入文件中,但由于某些原因我无法使用它。

谢谢!

【问题讨论】:

  • 尝试使用" 并使用\" 转义内部的。
  • @DanielA.White 这应该是一个答案。对于 Windows,这是必须的
  • @DanielA.White,这行得通!你能把它作为答案发布吗?

标签: json curl elasticsearch


【解决方案1】:

Windows 的cmd 不支持带单引号的字符串。使用" 并使用\" 转义内部的。

【讨论】:

  • 谢谢!这对我有很大帮助。
【解决方案2】:

“我搜索了解决方案,找到了替代方案,例如将json数据放入文件中,但由于某些原因我无法使用它”

这应该可以工作,hello.json 在 temp. @ 是必需的。

c:\temp>curl -v -X PUT  \ 
             --data "@hello.json"  \
             -H "Content-Type:application/json"  \
             http://localhost:8080/api/myresource

【讨论】:

    猜你喜欢
    • 2016-03-14
    • 2021-10-05
    • 2017-02-05
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多