加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

curl – 不支持Content-Type标头[application / x-www-form-urle

发布时间:2020-12-14 01:28:52 所属栏目:Linux 来源:网络整理
导读:参见英文答案 ElasticSearch – Content-Type header [application/x-www-form-urlencoded] is not supported????????????????????????????????????2个 我已将Elasticsearch(版本5.5)集成到Gitlab中并尝试使用它.这是我从外部Windows客户端发送的命令: curl
参见英文答案 > ElasticSearch – Content-Type header [application/x-www-form-urlencoded] is not supported????????????????????????????????????2个
我已将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"}}}'

但它不起作用.在客户端我得到这些错误:

{“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中的服务器上,我看不到日志消息.

但是,从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_type.required:true添加到elasticsearch.yml,但问题是一样的.那么,我在这里做错了什么?为什么我从Windows客户端获得“不支持Content-Type标头”?我怎么解决这个问题?

将’改为’后如下:

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

我接受了这个回复:

{
  "name" : "name",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"}}}"

alternative是将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 @json.txt

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读