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

问题描述

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

I have integrated Elasticsearch (Version 5.5) into Gitlab and try to use it. This is the command I send from an external windows client:

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

,但是它不起作用。在客户端上,我得到以下错误:

but it doesn't work. On the client I get these errors:

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

On the server in /var/log/elasticsearch/elasticsearch.log I can see no log messages.

但是,正在运行上面与Linux服务器相同的确切命令使我得到没有错误的响应:

However, running the same exact command as above from the linux server gives me a response without errors:

{
  "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_type.required:true 添加到elasticsearch.yml,但问题是相同的。那么,我在这里做错了什么?为什么从Windows客户端获取不支持Content-Type标头?我该如何解决?

I tried adding http.content_type.required: true to the elasticsearch.yml, but the problem was the same. So, what am I doing wrong here? Why do I get a "Content-Type header not supported" from the Windows client? How can I solve this?

在将更改为之后:

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


推荐答案

将封闭引号从'更改为 ,请在参数中使用引号 ,如下所示:

After changing the enclosing quotes from ' to ", escape the quotation marks " used inside the parameters as below:

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

另一个是将json放入文件中,并使用 @ 作为参数的前缀。

An alternative is to put the json into a file, and use the @ prefix for the parameters.

json.txt

{
  "query": {
    "simple_query_string" : {
      "fields" : ["content"],
      "query" : "foo bar -baz"
    }
  }
}

并按以下方式运行curl:

and run curl as below:

curl -XGET gitlab.server:9200/ -H "Content-Type: application/json" -d @json.txt

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

07-04 18:40