Elixir - HTTPoison


submit form data

  1. https://github.com/edgurgel/httpoison/blob/master/test/httpoison_test.exs
{:ok, %HTTPoison.Response{body: body}} = HTTPoison.post(
  "http://example.com",
  {:form, [key_1: "value_1", key_2: "value_2"]},
  %{"Content-Type" => "application/x-www-form-urlencoded"}
)

NOTE: Content-Type header is optional because we have explicitly specified that we are posting form data.

timeout vs. recv_timeout

  1. https://hexdocs.pm/httpoison/HTTPoison.Request.html#content

https://github.com/edgurgel/httpoison/issues/215

hackney returns {:error, :connect_timeout} when the connect_timeout is reached, and {:error, :timeout} when the recv_timeout is reached.

the confusion is because the HTTPoison option :timeout (which corresponds to hackney :connect_timeout) returns a :connect_timeout error, whereas the HTTPoison :recv_timeout returns the :timeout hackney error.

HTTPoison option hackney option hackney error
timeout connect_timeout connect_timeout
recv_timeout recv_timeout timeout
HTTPoison.get("http://google.com", [], [{:timeout, 1}])
# => {:error, %HTTPoison.Error{id: nil, reason: :connect_timeout}}
HTTPoison.get("http://google.com", [], [{:recv_timeout, 1}])
# => {:error, %HTTPoison.Error{id: nil, reason: :timeout}}