将HTTPS get请求发送到同一主机但不同的主机ips

时间:2018-04-16 13:58:13

标签: https erlang elixir httpoison

我想将HTTPS请求发送到同一主机,但我想每次都选择目标IP。

例如,“dig digitalocean.com”显示了这些IP:

digitalocean.com.   300 IN  A   104.16.110.208
digitalocean.com.   300 IN  A   104.16.112.208
digitalocean.com.   300 IN  A   104.16.109.208
digitalocean.com.   300 IN  A   104.16.113.208
digitalocean.com.   300 IN  A   104.16.111.208

使用HTTP可以:

HTTPoison.get("http://104.16.110.208/", [{"host","www.digitalocean.com"}])
{:ok,
 %HTTPoison.Response{body: "", headers: [...], request_url: "http://104.16.110.208/",
  status_code: 301}}

但是使用HTTPS我收到错误:

HTTPoison.get("https://104.16.110.208/", [{"host", "www.digitalocean.com"}])
{:error,
 %HTTPoison.Error{id: nil,
  reason: {:options, {{:server_name_indication, '104.16.110.208'}}}}}

有没有办法通过HTTPS使用HTTPoison实现这一点,或者在没有修改etc / hosts的情况下使用Elixir / Erlang实现此目的?

1 个答案:

答案 0 :(得分:2)

你需要像下面那样使用它

HTTPoison.get("https://104.16.110.208/", [{"host","www.digitalocean.com"}], hackney: [{:ssl_options, [{:server_name_indication, "digitalocean.com"}]}])

HTTPoison.get("https://104.16.110.208/", [{"host","www.digitalocean.com"}], hackney: [ssl_options: [server_name_indication: 'digitalocean.com']])

由于您使用IP进行连接,因此默认情况下server_name_indication将被视为IP。这是你需要覆盖的情况

Working