CURL:不支持Content-Type标头[application / x-www-form-urlencoded]

Abh*_*tti 1 curl elasticsearch

使用ElasticSearch并尝试一些查询以创建索引,然后使用curl发布数据。

使用GIT(Windows GIT)提供的卷曲

该命令用于将文档添加到名为customer的索引中。

从ElasticSearch网站复制curl命令,如下所示:

curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
  "name": "John Doe"
}
'
Run Code Online (Sandbox Code Playgroud)

上面的命令对我不起作用。我只将其如下所示

curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d '{"name": "John Doe"}'
Run Code Online (Sandbox Code Playgroud)

我收到以下错误。

请参考屏幕截图。

其他命令,例如创建索引,如下所示

curl -X PUT "localhost:9200/customer?pretty"

Response is :

{
      "acknowledged" : true,
      "shards_acknowledged" : true,
      "index" : "customer"
    }
Run Code Online (Sandbox Code Playgroud)

以json为内容的curl命令不起作用。

已经引用了以下链接,但无法获取它 内容类型问题

Val*_*Val 7

在Windows上,您需要使用双引号并将内容中的双引号转义:

curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H "Content-Type: application/json" -d "{\"name\": \"John Doe\"}"
Run Code Online (Sandbox Code Playgroud)

或者,您可以将内容存储在名为data.json的文件中

{"name": "John Doe"}
Run Code Online (Sandbox Code Playgroud)

然后像这样通过curl发送它,这样您就不必转义双引号了:

curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H "Content-Type: application/json" --data-binary @data.json
Run Code Online (Sandbox Code Playgroud)