Curl via script: Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}curl: (6) Could not resolve host: application


#1

Hi there,

I upgraded to 6.1.0 - coming from 5.1.2.
My script was running fine on 5.1.2 but I have problems with using scripted curl with 6.1.0. Maybe there is sth. wrong on my dev environment. Haven't reverted to 5.1.2. for proving that anything works there.

ok, here is my script:
#!/bin/bash

#setting some vars
curlArguments="-XGET http://localhost:9200/*/_search -H \"Content-Type: application/json\""
curlDataFile=./probe.curl

# building the command
mycommand="curl $curlArguments --data \"@$curlDataFile\""

# output of command
echo command is:
echo $mycommand
echo
echo "now firing command"

# firing the command
$mycommand

This is the content of the probe.curl file

{
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "*",
            "analyze_wildcard": true
          }
        },
        {
          "range": {
            "@timestamp": {
              "gte": "now/m-5m",
              "lte": "now/m",
              "format": "epoch_millis"
            }
          }
        }
      ],
      "must_not": []
    }
  },
  "size": "0"
}

When running, I got following output with error message:

command is:
curl -XGET http://localhost:9200/*/_search -H "Content-Type: application/json" --data "@./probe.curl"

now firing command
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}curl: (6) Could not resolve host: application; Der Name oder der Dienst ist nicht bekannt

The strange thing is, when I take the built command line

curl -XGET http://localhost:9200/*/_search -H "Content-Type: application/json" --data "@./probe.curl"

and run it directly from shell it works fine and I get following output:

{"took":14,"timed_out":false,"_shards":{"total":129,"successful":129,"skipped":128,"failed":0},"hits":{"total":78,"max_score":0.0,"hits":[]}}

Can anyone point to the root cause? I don't understand it.

Elasticsearch log is not showing anything, either on good or bad run.


#2

Yes, I reverted my VM to 5.1.2. Still working. What do I need to change to get it running with 6.1.0?


#3

found a solution. putting the header hardcoded is working:

#!/bin/bash

#setting some vars
curlArguments="-XGET http://localhost:9200/*/_search"
curlDataFile=./probe.curl

# building the command
myargs="$curlArguments ""--data \"@$curlDataFile\""
mycommand="curl $myargs"
curl -H 'Content-Type: application/json' $curlArguments --data "@$curlDataFile"

So it was just a quoting issue with the header which is needed by ES 6.x.


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.