如何使用 Erlang 发出 HTTPS 请求?

发布于 2024-09-03 01:27:10 字数 63 浏览 5 评论 0原文

我尝试了 inets 库,但它超时了。我认为它不支持 HTTPS。我正在尝试使用 ibrowse,但它不起作用。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

淡笑忘祈一世凡恋 2024-09-10 01:27:19

我来说,这适用于 Erlang/OTP 24 上的 Yaws 2.1.0 中的 get 请求(启用对等验证):

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"}]}], []).

否则将会出现警告:“真实性不是通过证书路径验证建立的”

对 更多选项请参见: https://www.erlang.org/doc/男人/httpc.html#request-4

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

溺渁∝ 2024-09-10 01:27:17

在 Erlang/OTP 25: 中,这对我有用:

httpc:request(get, {"https://erlang.com", []}, [{ssl, [{verify, verify_peer}, {cacerts, public_key:cacerts_get()}]}], []).

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

httpc:request(get, {"https://erlang.com", []}, [{ssl, [{verify, verify_peer}, {cacerts, public_key:cacerts_get()}]}], []).
倒数 2024-09-10 01:27:16

这对我有用:

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

httpc:request(head, {"https://example.com", []}, [{ssl,[{verify,0}]}], []).

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}]}], []).
霞映澄塘 2024-09-10 01:27:15

这对我来说效果很好:

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") 也可以,您只需在任何请求之前加载适当的应用程序即可。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文