How do I do an HTTPS request with Erlang?
Asked Answered
A

4

25

I tried the inets library but it times out. I don't think it supports HTTPS. I am trying to use ibrowse, but it isn't working.

Arbuthnot answered 22/5, 2010 at 1:5 Comment(1)
"It isn't working?" Post your errors! Post your code!Seraphina
S
31

This works fine for me:

1> application:start(inets).
ok
2> application:start(ssl).  
ok
3> http:request(head, {"https://example.com", []}, [{ssl,[{verify,0}]}], []).
{ok,{{"HTTP/1.1",200,"OK"},
     [{"cache-control","max-age=0, proxy-revalidate"},
      {"date","Sun, 23 May 2010 00:38:33 GMT"},
      {"server","BAIDA/1.0.0"},
      {"content-type","text/html; charset=windows-1251"},
      {"expires","Sun, 23 May 2010 00:38:33 GMT"},
      {"set-cookie",
       "uid=9041986921274575113; domain=.example.com; path=/; expires=Tue, 19 Jan 2038 03:14:07 GMT"}],
     []}}

http:request("https://example.com") would also work though, you just have to load appropriate applications before any request.

Sino answered 22/5, 2010 at 1:51 Comment(0)
D
3

This is what worked for me:

application:start(crypto),
application:start(public_key),
application:start(ssl),
application:start(inets).

httpc:request(head, {"https://example.com", []}, [{ssl,[{verify,0}]}], []).
Deeply answered 5/3, 2019 at 21:21 Comment(0)
E
2

In Erlang/OTP 25:, this worked for me:

httpc:request(get, {"https://erlang.com", []}, [{ssl, [{verify, verify_peer}, {cacerts, public_key:cacerts_get()}]}], []).
Exposition answered 23/9, 2022 at 0:7 Comment(0)
D
0

For me this worked for a get request (with peer verification enabled) in Yaws 2.1.0 on Erlang/OTP 24:

application:start(inets).
application:start(crypto).
application:start(asn1).
application:start(public_key).
application:start(ssl).

httpc:request(get, {"https://example.com", []}, 
    [{ssl, [{verify, verify_peer}, {cacertfile,"/path/to/cacertfile.crt"}]}], []).

Else there will be the warning: "Authenticity is not established by certificate path validation"

For more options see: https://www.erlang.org/doc/man/httpc.html#request-4

Damalis answered 1/2, 2022 at 23:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.