Erlang needs to connect to https server?

六眼飞鱼酱① 提交于 2019-12-06 16:49:01

The SSL module of Erlang/OTP which is the interface for Secure Socket Layer has an option for defining client side certificate:

{cacertfile, path()}

Path to a file containing PEM-encoded CA certificates. The CA certificates are used during server authentication and when building the client certificate chain.

Now if you want to use an HTTP client with the support of client side ssl certificate instead of writing everything by yourself, you have some options:

1. HTTPC: This is the default HTTP client of OTP.

SSLOptions = [{cacertfile, "/path/to/cert/file"}],
HTTPOptions = [{ssl, SSLOptions}],
%% ... define Method, Request and Options ...
httpc:request(Method, Request, HTTPOptions, Options),

2. Hackney: This is a third party and simple HTTP client.

SSLOptions = [{cacertfile, "/path/to/cert/file"}],
Options = [{ssl_options, SSLOptions}],
%% ... define Method, URL, Headers and Payload ...
hackney:request(Method, URL, Headers, Payload, Options),

Here you can see a full list of client side ssl options which can be used.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!