Content-Type header [application/x-www-form-urlencoded] is not supported
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\"}}}"
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"
}
}
}
and run curl as below:
curl -XGET gitlab.server:9200/ -H "Content-Type: application/json" -d @json.txt
Related videos on Youtube
waka
I work in software developement anduse a wide range of technologies (JavaScript, PHP, VB, VB.NET) but I am most comfortable with C#. I also have a basic knowledge of Java.
Updated on January 18, 2020Comments
-
waka over 4 years
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:
{"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 13On the server in /var/log/elasticsearch/elasticsearch.log I can see no log messages.
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" }
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?After changing the ' to " like this:
curl -XGET gitlab.server:9200/ -H "Content-Type: application/json" -d "{"query": {"simple_query_string" : {"fields" : ["content"], "query" : "foo bar -baz"}}}"
I recieve this response:
{ "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
-
Bless over 6 yearsLooks like an issue with quotes on windows. Check stackoverflow.com/questions/11834238/… and stackoverflow.com/questions/44680899/…
-
waka over 6 years@bless: See my edit. It looks better (as in, I actually recieve a response) but there still seems to be something wrong with the command.
-
Bless over 6 yearsCan you update the question with the command you ran after changing the ' to "?
-
waka over 6 years@bless: I did as you asked.
-
Bless over 6 yearsThink you might have to escape the quotes
-d "{\"query\": {\"simple_query_string\" : {\"fields\" : [\"content\"], \"query\" : \"foo bar -baz\"}}}"
-
waka over 6 years@bless: Okay, I will try that on monday. Cheers!
-
waka over 6 years@bless: I now tried it with escaped quotation marks and got a response without any error messages. Please post this as an answer so I can accept it. Thanks for your help! :)
-
Bless over 6 yearsPosted as an answer. Cheers!
-
Fede Garcia over 2 yearsIn my case it worked just by providing the option
-H "Content-Type: application/json"
which I was missing. Thanks for making the question :) -
waka over 2 years@FedeGarcia Cheers. Judging from all the upvotes this question received, we are not alone with problems like this. ;)
-