CURL:不支持Content-Type标头[application/x-www-form-urlencoded] [英] CURL : Content-Type header [application/x-www-form-urlencoded] is not supported

查看:60
本文介绍了CURL:不支持Content-Type标头[application/x-www-form-urlencoded]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用ElasticSearch并尝试一些查询来创建索引,使用curl来发布数据.

Working on ElasticSearch and trying some queries for creating index, posting data using the curl.

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

Using the curl provided by GIT(Windows GIT)

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

The command goes to add a document to a index named customer.

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

The curl command from the ElasticSearch site it is copied as below :

curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
  "name": "John Doe"
}
'

以上命令对我不起作用.我只是将其做成一行,如下所示

The above command does not work for me. I just make it a single line as below

curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d '{"name": "John Doe"}'

我收到以下错误.

其他命令(如创建索引)的运行方式如下

Other command like creating an index run like below

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

Response is :

{
      "acknowledged" : true,
      "shards_acknowledged" : true,
      "index" : "customer"
    }

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

The curl command having the json as content are not working.

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

Already referred the below link but could not get it Content Type Issue

推荐答案

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

On Windows, you need to use double quotes and escape the ones in the content:

curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H "Content-Type: application/json" -d "{\"name\": \"John Doe\"}"

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

Alternatively, you can store the content in a file called data.json

{"name": "John Doe"}

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

And then send it via curl like this so you don't have to escape the double quotes:

curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H "Content-Type: application/json" --data-binary @data.json

这篇关于CURL:不支持Content-Type标头[application/x-www-form-urlencoded]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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