我想将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实现此目的?
答案 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。这是你需要覆盖的情况