使用 Hackney 适配器在 Tesla 中使用代理和禁用 SSL

Using a proxy and disabling SSL in Tesla using Hackney adapter

这是我阅读文档后正在做的事情。我想在每个模块的基础上使用它,所以它就在模块中。此方法基于 this answer.

defmodule MyModule do
    use Tesla
    adapter Tesla.Adapter.Hackney, proxy: {"http://proxy.example.com", 5555}, ssl: {:verify, :verify_none}

但是,我一直收到 :nxdomain 错误。预期的行为是让 HTTP 请求使用代理并忽略任何 SSL 证书错误。

根据 Hackney 文档,proxy 选项是简单的 URL 或主机+端口元组。尝试将其更改为:

proxy: {"proxy.example.com", 5555}

proxy: "http://proxy.example.com:5555"

想通了。以下是设置代理和禁用 SSL 检查的方法。我正在使用带有 Hackney 适配器的 Tesla:

defmodule MyModule do
  use Tesla
  adapter Tesla.Adapter.Hackney, proxy: "https://proxy.example.com:5000", ssl_options: [verify: :verify_none]

如果您想分别指定主机和端口,则为:

defmodule MyModule do
  use Tesla
  adapter Tesla.Adapter.Hackney, proxy: {"https://proxy.example.com", 5000}, ssl_options: [verify: :verify_none]