elasticsearch,curl,elixir,Http,elasticsearch,Curl,Elixir" /> elasticsearch,curl,elixir,Http,elasticsearch,Curl,Elixir" />

对elasticsearch服务器的Httpoison请求给了我EconRecursed错误,而卷曲同样的东西不会';T

对elasticsearch服务器的Httpoison请求给了我EconRecursed错误,而卷曲同样的东西不会';T,http,elasticsearch,curl,elixir,Http,elasticsearch,Curl,Elixir,当我尝试使用httpoison查询elasticsearch服务器时,例如 iex(1)> HTTPoison.get "http://localhost:9200" 我明白了 {:error, %HTTPoison.Error{id: nil, reason: :econnrefused}}. 如果我这样做 curl -XGET "http://localhost:9200" 我明白了 有人知道这种行为是由什么引起的,以及如何修复它吗 注意:将localhost更改为127.0.0

当我尝试使用httpoison查询elasticsearch服务器时,例如

iex(1)> HTTPoison.get "http://localhost:9200"
我明白了

{:error, %HTTPoison.Error{id: nil, reason: :econnrefused}}.
如果我这样做

curl -XGET "http://localhost:9200"
我明白了

有人知道这种行为是由什么引起的,以及如何修复它吗

注意:将localhost更改为127.0.0.1并不能解决问题。

以下是我的设置:

elasticsearch Version: 7.0.1
{:httpoison, "~> 1.5"}  #=> mix.lock shows version 1.5.1 was installed
卷曲结果

$ curl -XGET "http://localhost:9200"
{
  "name" : "My-MacBook-Pro.local",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "vEFl3B5TTYaBxPhQFuXPyQ",
  "version" : {
    "number" : "7.0.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "e4efcb5",
    "build_date" : "2019-04-29T12:56:03.145736Z",
    "build_snapshot" : false,
    "lucene_version" : "8.0.0",
    "minimum_wire_compatibility_version" : "6.7.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
HTTPoison结果:

$ iex -S mix
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]

===> Compiling parse_trans
===> Compiling mimerl
===> Compiling metrics
===> Compiling unicode_util_compat
===> Compiling idna
==> ssl_verify_fun
Compiling 7 files (.erl)
Generated ssl_verify_fun app
===> Compiling certifi
===> Compiling hackney
==> httpoison
Compiling 3 files (.ex)
Generated httpoison app
==> hello
Compiling 15 files (.ex)
Generated hello app
Interactive Elixir (1.6.6) - press Ctrl+C to exit (type h() ENTER for help)

iex(1)> HTTPoison.get "http://localhost:9200"
{:ok,
 %HTTPoison.Response{
   body: "{\n  \"name\" : \"My-MacBook-Pro.local\",\n  \"cluster_name\" :  
\"elasticsearch\",\n  \"cluster_uuid\" : \"vEFl3B5TTYaBxPhQFuXPyQ\",\n  
\"version\" : {\n    \"number\" : \"7.0.1\",\n    \"build_flavor\" :   
\"default\",\n    \"build_type\" : \"tar\",\n    \"build_hash\" :   
\"e4efcb5\",\n    \"build_date\" : \"2019-04-29T12:56:03.145736Z\",\n  
\"build_snapshot\" : false,\n    \"lucene_version\" : \"8.0.0\",\n  
\"minimum_wire_compatibility_version\" : \"6.7.0\",\n  
\"minimum_index_compatibility_version\" : \"6.0.0-beta1\"\n  },\n  
\"tagline\" : \"You Know, for Search\"\n}\n",
   headers: [
     {"content-type", "application/json; charset=UTF-8"},
     {"content-length", "522"}
   ],
   request: %HTTPoison.Request{ 
     body: "",
     headers: [],
     method: :get,
     options: [],
     params: %{},
     url: "http://localhost:9200"
   },
   request_url: "http://localhost:9200",
   status_code: 200
 }}

iex(2)> 
接下来,我停止elasticsearch服务器,然后再次运行HTTPoison请求:

ex(2)> HTTPoison.get "http://localhost:9200"
{:error, %HTTPoison.Error{id: nil, reason: :econnrefused}}
对于curl请求,我得到了类似的结果:

$ curl -XGET "http://localhost:9200"
curl: (7) Failed to connect to localhost port 9200: Connection refused
如果连续发出两个curl请求,会发生什么?他们都成功了吗?尝试先发出HTTPoison请求,然后发出curl请求。哪一个失败了?试试相反的顺序。相同的结果?

这是我的设置:

elasticsearch Version: 7.0.1
{:httpoison, "~> 1.5"}  #=> mix.lock shows version 1.5.1 was installed
卷曲结果

$ curl -XGET "http://localhost:9200"
{
  "name" : "My-MacBook-Pro.local",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "vEFl3B5TTYaBxPhQFuXPyQ",
  "version" : {
    "number" : "7.0.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "e4efcb5",
    "build_date" : "2019-04-29T12:56:03.145736Z",
    "build_snapshot" : false,
    "lucene_version" : "8.0.0",
    "minimum_wire_compatibility_version" : "6.7.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
HTTPoison结果:

$ iex -S mix
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]

===> Compiling parse_trans
===> Compiling mimerl
===> Compiling metrics
===> Compiling unicode_util_compat
===> Compiling idna
==> ssl_verify_fun
Compiling 7 files (.erl)
Generated ssl_verify_fun app
===> Compiling certifi
===> Compiling hackney
==> httpoison
Compiling 3 files (.ex)
Generated httpoison app
==> hello
Compiling 15 files (.ex)
Generated hello app
Interactive Elixir (1.6.6) - press Ctrl+C to exit (type h() ENTER for help)

iex(1)> HTTPoison.get "http://localhost:9200"
{:ok,
 %HTTPoison.Response{
   body: "{\n  \"name\" : \"My-MacBook-Pro.local\",\n  \"cluster_name\" :  
\"elasticsearch\",\n  \"cluster_uuid\" : \"vEFl3B5TTYaBxPhQFuXPyQ\",\n  
\"version\" : {\n    \"number\" : \"7.0.1\",\n    \"build_flavor\" :   
\"default\",\n    \"build_type\" : \"tar\",\n    \"build_hash\" :   
\"e4efcb5\",\n    \"build_date\" : \"2019-04-29T12:56:03.145736Z\",\n  
\"build_snapshot\" : false,\n    \"lucene_version\" : \"8.0.0\",\n  
\"minimum_wire_compatibility_version\" : \"6.7.0\",\n  
\"minimum_index_compatibility_version\" : \"6.0.0-beta1\"\n  },\n  
\"tagline\" : \"You Know, for Search\"\n}\n",
   headers: [
     {"content-type", "application/json; charset=UTF-8"},
     {"content-length", "522"}
   ],
   request: %HTTPoison.Request{ 
     body: "",
     headers: [],
     method: :get,
     options: [],
     params: %{},
     url: "http://localhost:9200"
   },
   request_url: "http://localhost:9200",
   status_code: 200
 }}

iex(2)> 
接下来,我停止elasticsearch服务器,然后再次运行HTTPoison请求:

ex(2)> HTTPoison.get "http://localhost:9200"
{:error, %HTTPoison.Error{id: nil, reason: :econnrefused}}
对于curl请求,我得到了类似的结果:

$ curl -XGET "http://localhost:9200"
curl: (7) Failed to connect to localhost port 9200: Connection refused

如果连续发出两个curl请求,会发生什么?他们都成功了吗?尝试先发出HTTPoison请求,然后发出curl请求。哪一个失败了?试试相反的顺序。同样的结果?

我几乎可以肯定你和我有同样的问题。检查以确保您没有在/etc/hosts文件中强制使用ipv6

如果你有这样的东西:

::1本地主机


…扔掉它,Httpoison应该会再次工作

我几乎可以肯定你和我有同样的问题。检查以确保您没有在/etc/hosts文件中强制使用ipv6

如果你有这样的东西:

::1本地主机


…扔掉它,Httpoison应该会再次工作

我不认为是这样,但为了排除它,Httpoison.gethttp://localhost:9200/“work?不幸的是,我在尝试当前版本之前就尝试过了。它是否适用于httpc?尝试此
应用程序。确保所有应用程序都已启动(:inets);:httpc.request'http://localhost:9200/“
(注意单引号)
httpc
随Erlang提供,因此您不需要安装任何东西。同样的混乱:Interactive Elixir(1.8.1)-按Ctrl+C退出(键入h()ENTER以获取帮助)iex(1)>应用程序。确保所有应用程序都已启动(:inets);:httpc.request'{:error,{:failed_connect,[{:to_address,{'localhost',9200}},{:inet,[:inet],:econnrefused}}}}}和curling再次授予访问权限,就像授予firefox一样。我不认为是这样,但为了排除它,
HTTPoison.get”http://localhost:9200/“
工作?不幸的是,在我尝试当前版本之前,我已经尝试过了。它是否适用于httpc?尝试此
应用程序。确保所有应用程序都已启动(:inets);:httpc.request'http://localhost:9200/“
(注意单引号)
httpc
随Erlang提供,因此您不需要安装任何东西。同样的混乱:Interactive Elixir(1.8.1)-按Ctrl+C退出(键入h()ENTER以获取帮助)iex(1)>应用程序。确保所有应用程序都已启动(:inets);:httpc.request'{:error,{:failed_connect,[{:to_address,{'localhost',9200}},{:inet,[:inet],:econnrefused}}}}和curling再次授予访问权限以及firefox。请注意,在绝大多数情况下,侦听本地使用的
tcp6
协议的服务将显示在
netstat
或具有IPv6地址的类似工具中(如上面的回答所示)。这些
tcp6
sockets可与ipv4和ipv6地址一起工作。请注意,在绝大多数情况下,侦听本地使用的
tcp6
协议的服务将在
netstat
或具有IPv6地址的类似工具中显示自己(如上面的答案所示)。这些
tcp6
sockets可与ipv4和ipv6地址一起工作。