I want to use :httpc
as my HTTP client.
I use edeliver for my release management and such. I have :inets
and :httpc
in my .deliver/config.exs
like:
set applications: [
:runtime_tools,
:inets,
:httpc
]
I also added :inets
to :extra_applications
in mix.exs
.
Here is how I use :httpc
:
headers =
if apikey,
do: [{'Content-Type', 'application/json'}, {'apikey', to_charlist(apikey)}],
else: [{'Content-Type', 'application/json'}]
http_options = [timeout: @timeout, connect_timeout: @timeout]
options = []
request = {
to_charlist(url),
headers,
'application/json',
to_charlist(encoded_obj)
}
:post
|> :httpc.request(request, http_options, options)
|> handle_response()
I get a lot of errors like:
=SUPERVISOR REPORT==== 6-Mar-2018::15:44:11 ===
Supervisor: {local,httpc_handler_sup}
Context: child_terminated
Reason: {function_clause,
[{http_transport,close,
[undefined,#Port<0.21557>],
[{file,"http_transport.erl"},{line,346}]},
{gen_server,try_terminate,3,
[{file,"gen_server.erl"},{line,648}]},
{gen_server,terminate,10,
[{file,"gen_server.erl"},{line,833}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,247}]}]}
Offender: [{pid,<0.2596.1>},
{id,undefined},
{mfargs,{httpc_handler,start_link,undefined}},
{restart_type,temporary},
{shutdown,4000},
{child_type,worker}]
and also
15:44:11.743 [error] GenServer #PID<0.2595.1> terminating
** (FunctionClauseError) no function clause matching in :http_transport.close/2
(inets) http_transport.erl:346: :http_transport.close(:undefined, #Port<0.21559>)
(stdlib) gen_server.erl:648: :gen_server.try_terminate/3
(stdlib) gen_server.erl:833: :gen_server.terminate/10
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: {:init_error, :error_sending, {#Reference<0.18155839.2531262466.203553>, {:error, :einval}}}
which are the same error reported differently.
This line says something that I don't get too:
15:44:11.741 [error] Bad value on output port 'tcp_inet'
I don't actually get why this happens.
I was using HTTPotion
and that did not have this problem (had others though).
The thing is this works on my dev machine. It also works on a production-like VM that is on my machine too. But it throws this error when it goes on real production server.
I'm so confused!