title: Elixir - problems with https URLs
body: <p>I'm new to Elixir and Erlang and having some issues with accessing https URLs. I've tried the Elixir-specific <strong>HTTPotion</strong> and Erlang's <strong>:inets</strong> module.</p>
  
  <p>So from the iex console (Interactive Elixir):</p>
  
  <p>With HTTPotion:</p>
  
  <pre><code>HTTPotion.start
  HTTPotion.get("https://api.github.com")
  </code></pre>
  
  <p>With :inets:</p>
  
  <pre><code>:inets.start
  :ssl.start
  :httpc.request('https://api.github.com')
  </code></pre>
  
  <p>In both cases I get a giant stacktrace that essential says there is a bad match somewhere and that a state machine is terminating. I don't get this when accessing http URLs. What am I missing? Thanks.</p>
  
  <p><strong>Edit - here is the error message from HTTPotion:</strong></p>
  
  <pre><code>iex(40)&gt; HTTPotion.get("https://api.github.com") 
  ** (Protocol.UndefinedError) protocol String.Chars not implemented for {:EXIT, {{{{:badmatch, ""}, [{:ssl_handshake, :dec_hello_extensions, 2, [file: 'ssl_handshake.erl', line: 1737]}, {:ssl_handshake, :decode_handshake, 3, [file: 'ssl_handshake.erl', line: 926]}, {:tls_handshake, :get_tls_handshake_aux, 3, [file: 'tls_handshake.erl', line: 155]}, {:tls_connection, :next_state, 4, [file: 'tls_connection.erl', line: 433]}, {:gen_fsm, :handle_msg, 7, [file: 'gen_fsm.erl', line: 503]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 237]}]}, {:gen_fsm, :sync_send_all_state_event, [#PID&lt;0.227.0&gt;, {:start, 5000}, :infinity]}}, {:gen_server, :call, [#PID&lt;0.226.0&gt;, {:send_req, {{:url, 'https://api.github.com', 'api.github.com', 443, :undefined, :undefined, '/', :https, :hostname}, [], :get, "", [], 5000}}, 5000]}}}
         (elixir) lib/string/chars.ex:3: String.Chars.impl_for!/1
         (elixir) lib/string/chars.ex:17: String.Chars.to_string/1
      (httpotion) lib/httpotion.ex:157: HTTPotion.request/5
  iex(40)&gt; 
  16:50:10.640 [error] ** State machine #PID&lt;0.227.0&gt; terminating 
  ** Last message in was {:tcp, #Port&lt;0.7454&gt;,
   &lt;&lt;22, 3, 3, 0, 93, 2, 0, 0, 89, 3, 3, 84, 40, 158, 178, 2, 216, 45, 226, 183, 79, 42, 199, 205, 19, 31, 63, 223, 138, 208, 132, 186, 28, 129, 123, 235, 1, 142, 90, 243, 25, 70, 210, 32, 199, 56, 251, 131, ...&gt;&gt;}
  ** When State == :hello
  **      Data  == [data: [{'StateData',
     {:state, :client, {#Reference&lt;0.0.0.1360&gt;, #PID&lt;0.226.0&gt;}, :gen_tcp,
      :tls_connection, :tcp, :tcp_closed, :tcp_error, 'api.github.com', 443,
      #Port&lt;0.7454&gt;,
      {:ssl_options, :tls, [{3, 3}, {3, 2}, {3, 1}, {3, 0}], :verify_none,
       {#Function&lt;7.50551058/3 in :ssl.handle_verify_options/2&gt;, []},
       #Function&lt;8.50551058/1 in :ssl.handle_verify_options/2&gt;, false, false,
       :undefined, 1, "", '***', "", '***', '***', '***', "", '***', :undefined,
       :undefined, '***', '***',
       [&lt;&lt;192, 36&gt;&gt;, &lt;&lt;192, 40&gt;&gt;, &lt;&lt;192, 38&gt;&gt;, &lt;&lt;192, 42&gt;&gt;, &lt;&lt;0, 107&gt;&gt;,
        &lt;&lt;0, 106&gt;&gt;, &lt;&lt;0, 61&gt;&gt;, &lt;&lt;192, 35&gt;&gt;, &lt;&lt;192, 39&gt;&gt;, &lt;&lt;192, 37&gt;&gt;, &lt;&lt;192, 41&gt;&gt;, 
        &lt;&lt;0, 103&gt;&gt;, &lt;&lt;0, ...&gt;&gt;, &lt;&lt;...&gt;&gt;, ...],
       #Function&lt;1.50551058/4 in :ssl.handle_options/1&gt;, true, 268435456, false,
       :undefined, false, :undefined, :undefined, true, :undefined, false},
      {:socket_options, :binary, 0, 0, 0, false}, '***', '***', '***', 49168,
      '***', 61463, :ssl_session_cache, {3, 3}, false, :undefined,
      {:undefined, :undefined}, :undefined, :undefined, '***', '***', '***',
      :undefined, '***', '***', '***', 53269, #Reference&lt;0.0.0.1363&gt;, :undefined,
      '***', {false, :first}, {#PID&lt;0.226.0&gt;, #Reference&lt;0.0.0.1361&gt;},
      #Reference&lt;0.0.0.1364&gt;, {[], []}, false, true, false, false, :undefined,
      :undefined, :undefined}}]]
  ** Reason for termination = 
  ** {{:badmatch, ""},
   [{:ssl_handshake, :dec_hello_extensions, 2,
     [file: 'ssl_handshake.erl', line: 1737]},
    {:ssl_handshake, :decode_handshake, 3,
     [file: 'ssl_handshake.erl', line: 926]},
    {:tls_handshake, :get_tls_handshake_aux, 3,
     [file: 'tls_handshake.erl', line: 155]},
    {:tls_connection, :next_state, 4, [file: 'tls_connection.erl', line: 433]},
    {:gen_fsm, :handle_msg, 7, [file: 'gen_fsm.erl', line: 503]},
    {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 237]}]}
  
  
  16:50:10.642 [error] GenServer #PID&lt;0.226.0&gt; terminating
  Last message: {:send_req, {{:url, 'https://api.github.com', 'api.github.com', 443, :undefined, :undefined, '/', :https, :hostname}, [], :get, "", [], 5000}}
  State: {:state, 'api.github.com', 443, :undefined, #Reference&lt;0.0.0.1352&gt;, false, :undefined, [], true, :undefined, false, [], {[], []}, :undefined, :idle, :undefined, "", 0, 0, [], :undefined, :undefined, :undefined, :undefined, false, :undefined, :undefined, "", :undefined, false, 188446, 0, :undefined}
  ** (exit) exited in: :gen_fsm.sync_send_all_state_event(#PID&lt;0.227.0&gt;, {:start, 5000}, :infinity)
      ** (EXIT) an exception was raised:
          ** (MatchError) no match of right hand side value: ""
              (ssl) ssl_handshake.erl:1737: :ssl_handshake.dec_hello_extensions/2
              (ssl) ssl_handshake.erl:926: :ssl_handshake.decode_handshake/3
              (ssl) tls_handshake.erl:155: :tls_handshake.get_tls_handshake_aux/3
              (ssl) tls_connection.erl:433: :tls_connection.next_state/4
              (stdlib) gen_fsm.erl:503: :gen_fsm.handle_msg/7
              (stdlib) proc_lib.erl:237: :proc_lib.init_p_do_apply/3
  
  nil
  iex(41)&gt; 
  </code></pre>