不支持Content-Type标头[application / x-www-form-urlencoded] [英] Content-Type header [application/x-www-form-urlencoded] is not supported
问题描述
我已将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:
{错误:内容类型标头[application / x-www-form-urlencoded ]不被支持,状态:406}
curl:(6)无法解析主机:text
curl:(3)[globbing]列1中的括号不匹配
curl:(3)错误的URL,冒号是第一个字符
curl:(3)第1列中的括号不匹配
curl:(3 )错误的URL,冒号是第一个字符
curl:(3)第2列中的[globbing]范围错误
curl:(6)无法解析主机:query
curl:(3)错误的URL,冒号是第一个字符
curl:(3)第13列中的[globbing]不匹配的大括号/括号
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}
curl: (6) Could not resolve host: text
curl: (3) [globbing] unmatched brace in column 1
curl: (3) Bad URL, colon is first character
curl: (3) [globbing] unmatched brace in column 1
curl: (3) Bad URL, colon is first character
curl: (3) [globbing] bad range in column 2
curl: (6) Could not resolve host: query
curl: (3) Bad URL, colon is first character
curl: (3) [globbing] unmatched close brace/bracket in column 13
在/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]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!