I have this:
HTTPoison.start
case HTTPoison.get("some url") do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
IO.puts(body)
Which produces an exception:
Generated escript grex_cli with MIX_ENV=dev
** (ArgumentError) argument error
(stdlib) :io.put_chars(#PID<0.49.0>, :unicode, [<<60, 33, 100, 111,..... 58, ...>>, 10])
(elixir) lib/kernel/cli.ex:76: anonymous fn/3 in Kernel.CLI.exec_fun/2
How can I read the body and print it?
IO.inspect(body)
. Does that URL return a binary file? – Dogbert<<60, 33, 100, 111, 99.....
How can I decode that to a text? – user7040064<<60, 33, 100, 111, 99>> #=> "<!doc"
looks like you're fetching an HTML page? That page seems to have invalid UTF-8 content somewhere. Would it be possible to share the actual URL? In any case, if you just want to write that to the terminal, you can doIO.binwrite(body)
. – Dogbertbinwrite
work for that? – user7040064IO.binwrite
will just let you write the body to a file or stdout and fix the original problem in the question thatIO.puts
doesn't print the body. – Dogbert