11

I'm pretty new to elixir and have no erlang experience (or func-y stuff) but that will soon become apparent.. ->

iex(2)> :inets.start()
:ok
iex(3)> :httpc.request(["http://www.erlang.org"])
{:error, :no_scheme}

I have no idea what :no_scheme means. I've googled no_scheme and stuff and I'm sure it's obvious, but I found nothing really. The only vaguely related thing I could find in the erlang docs was ->

iex(4)> :http_uri.scheme_defaults
[http: 80, https: 443, ftp: 21, ssh: 22, sftp: 22, tftp: 69]

or maybe I wasn't conforming to RFC2616 or something... I'm out of ideas (for now).

Elixir and Erlang are super super awesome though so any help in furthering my journey would be appreciated.

Thanks for any help!

I tried it out in erl.

1> inets:start().
ok
2> httpc:request("http://www.erlang.org").
{ok,{{"HTTP/1.1",200,"OK"},
     [{"date","Wed, 20 Nov 2013 23:15:45 GMT"},
      {"server","inets/5.7.1"},
      {"content-length","10385"},
      {"content-type","text/html; charset=utf-8"},
      {"set-cookie",
       "eptic_cookie=erlangorg@hades-3680318586833850369; path=/"}],
        "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE htm
    etc...

Edit:

Ok so, my biggest problem was I was double quoting "http://www.erlang.org" the strings and I'm guess elixir -> erlang takes them in as single quoted like parrotys answer 'http://www.erlang.org'.

no_scheme still pretty cryptic. All I could find was stuff relating to redirects and the RFC implementation. I've just decided to consider it a generic error, something to do with the url..

Edit 2:

There's a blog post here by someone that explains it well. Link

Erlang atoms like database become :database and a local variable like PgConn in the Erlang version becomes pg_conn in Elixir.

We need to single-quote string literals when they are arguments to an Erlang function. If you have a UTF-8 string stored in an Elixir variable, you can convert it to a char list with the binary_to_list/1 function.

Edit 3:

Ironically the latest Elixir Sip titled "HTTP clients" that came out a few hours ago covers my entire question. Check it out anyone coming across this is the future!

3
  • When interfacing with Erlang code, the crash course is very handy: elixir-lang.org/crash-course.html Nov 21, 2013 at 9:16
  • I've been over that a few times the last couple days but couldn't find anything. There's the bit about Erlang -> Elixir at the end but not the other way round (unless I keep missing it). I just refound this which I now realise was all I needed. I was only looking for how to do the get -> :get thing and never noticed the difference in the strings. Also thanks a lot in general! I'm having an awesome time. Ahh I just saw the author of that link explained everything.. That will teach me for scanning.
    – Willl
    Nov 21, 2013 at 10:20
  • 1
    Scheme is the first part of url. For example "http://", "https://". If you used binary instead of list, it wasn't able to read it properly. This caused :no_scheme error.
    – tkowal
    Jul 25, 2015 at 21:09

3 Answers 3

19

How is the following?

:inets.start
:httpc.request(:get, {'http://www.erlang.org', []}, [], [])
1
  • I was still getting {:error, {:failed_connect, [{:to_address, {'www.erlang.org', 443}}, {:inet, [:inet], :ssl_not_started}]}} despite requesting the 'http' protocol and I fixed calling :ssl.start as suggested below by @pob . I guess a redirect to https was forced on the server side.
    – acorello
    Apr 4, 2021 at 16:01
12

For https requests, there is one additional step - the need for SSL:

> :inets.start
> :ssl.start
> :httpc.request ‘https://elixir-lang.org'

Note the shorter request format.

I am using IEx 1.7.3 (compiled with Erlang/OTP 21).

11

"" in erlang is char list while in elixir is ''("" in elixir is binary)

you can use :httpc.request('http://www.erlang.org') shortly

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.