RailsDFW
RailsDFW

Reputation: 1573

Setting httpc proxy in iex (Phoenix project)

My query to Wolfram Alpha fails when using iex behind a proxy. I tried setting the proxy using

iex(1)> :httpc.set_options({:proxy, {"proxy.mycompany.org", 1234}})

but this is giving a CaseClauseError error. How do I set options within iex for this Erlang library? Thank you.

Background: I am going through the book "Programming Phoenix"

Upvotes: 0

Views: 359

Answers (1)

Dogbert
Dogbert

Reputation: 222318

Three things:

  1. set_options accepts a list of options, not one option.

  2. The hostname must be an Erlang string, which is called a charlist in Elixir, and is created using single quotes in Elixir.

  3. That option requires a tuple {Proxy, NoProxy} where NoProxy is a list of NoProxyDesc options. You might want to read the documentation for that; I'm using an empty list below.

You can also use the keyword list syntax to make this slightly shorter:

iex(1)> :httpc.set_options([{:proxy, {{'proxy.mycompany.org', 1234}, []}}])
:ok

You can also use the keyword list syntax to make this slightly shorter:

iex(2)> :httpc.set_options([proxy: {{'proxy.mycompany.org', 1234}, []}])
:ok

Upvotes: 3

Related Questions