不支持内容类型标题[application/x-www-form-urlencoded]

不支持内容类型标题[application/x-www-form-urlencoded],
Warning: implode(): Invalid arguments passed in /data/phpspider/zhask/webroot/tpl/detail.html on line 45
,,我已经将Elasticsearch(5.5版)集成到Gitlab中并尝试使用它。这是我从外部windows客户端发送的命令: curl -XGET gitlab.server:9200/ -H 'Content-Type: application/json' -d '{"query": {"simple_query_string" : {"fields" : ["content"], "query" : "foo bar -baz"}}}' 但它不起作用。在客户端上,我收到以下错误: {“错误

我已经将Elasticsearch(5.5版)集成到Gitlab中并尝试使用它。这是我从外部windows客户端发送的命令:

curl -XGET gitlab.server:9200/ -H 'Content-Type: application/json' -d '{"query": {"simple_query_string" : {"fields" : ["content"], "query" : "foo bar -baz"}}}'
但它不起作用。在客户端上,我收到以下错误:

{“错误”:“不支持内容类型头[application/x-www-form-urlencoded],“状态”:406}
curl:(6)无法解析主机:文本
卷曲:(3)[globbing]第1列中的大括号不匹配
curl:(3)错误的URL,冒号是第一个字符
卷曲:(3)[globbing]第1列中的大括号不匹配
curl:(3)错误的URL,冒号是第一个字符
卷曲:(3)[globbing]列2中的范围不正确
curl:(6)无法解析主机:查询
curl:(3)错误的URL,冒号是第一个字符
卷曲:(3)[球形]第13列中不匹配的右括号/括号

在/var/log/elasticsearch/elasticsearch.log中的服务器上,我看不到任何日志消息

但是,从linux服务器上运行与上述相同的确切命令时,会给出一个无错误的响应:

{
  "name" : "name",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "uuid",
  "version" : {
    "number" : "5.5.0",
    "build_hash" : "260387d",
    "build_date" : "2017-06-30T23:16:05.735Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.0"
  },
  "tagline" : "You Know, for Search"
}
我尝试将
http.content\u type.required:true
添加到elasticsearch.yml,但问题是相同的。那么,我做错了什么?为什么要从Windows客户端获取“不支持的内容类型头”?我怎样才能解决这个问题

将“更改为”后,如下所示:

curl -XGET gitlab.server:9200/ -H "Content-Type: application/json" -d "{"query": {"simple_query_string" : {"fields" : ["content"], "query" : "foo bar -baz"}}}"
我收到这样的答复:

{
  "name" : "name",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "uuid",
  "version" : {
    "number" : "5.5.0",
    "build_hash" : "260387d",
    "build_date" : "2017-06-30T23:16:05.735Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.0"
  },
  "tagline" : "You Know, for Search"
}
curl: (6) Could not resolve host: bar

将括起的引号从
更改为
后,将参数内使用的引号
转义如下:

curl -XGET gitlab.server:9200/ -H "Content-Type: application/json" -d "{\"query\": {\"simple_query_string\" : {\"fields\" : [\"content\"], \"query\" : \"foo bar -baz\"}}}"
curl -XGET gitlab.server:9200/ -H "Content-Type: application/json" -d @json.txt
一种方法是将json放入一个文件中,并使用
@
前缀作为参数

json.txt

{
  "query": {
    "simple_query_string" : { 
      "fields" : ["content"], 
      "query" : "foo bar -baz"
    }
  }
}
然后运行curl,如下所示:

curl -XGET gitlab.server:9200/ -H "Content-Type: application/json" -d "{\"query\": {\"simple_query_string\" : {\"fields\" : [\"content\"], \"query\" : \"foo bar -baz\"}}}"
curl -XGET gitlab.server:9200/ -H "Content-Type: application/json" -d @json.txt

windows上的引号似乎有问题。请检查并@bless:查看我的编辑。它看起来更好(如中所示,我实际上收到了响应),但该命令似乎仍有问题。您能否使用更改“到”后运行的命令更新该问题?@bless:我照你说的做了。@bless:我现在用转义引号试了一下,没有收到任何错误消息。请将此作为答案发布,以便我可以接受。谢谢你的帮助!:)