【发布时间】:2016-09-26 17:44:29
【问题描述】:
这是我第一次使用 erlang,我决定尝试为 API 编写一个包装器。这是我到目前为止所得到的:-
-module(my_api_wrapper).
%% API exports
-export([auth/0]).
auth() ->
application:start(inets),
application:start(ssl),
AuthStr = base64:encode_to_string("username:password"),
Method = post,
URL = "https://api.endpoint.com/auth",
Header = [{"Authorization", "Basic " ++ AuthStr}],
Type = "application/json",
Body = "{\"grant_type\":\"client_credentials\"}",
HTTPOptions = [],
Options = [],
httpc:request(Method, {URL, Header, Type, Body}, HTTPOptions, Options).
在 shell 上进行测试时出现错误:-
{error,{failed_connect,[{to_address,{"api.endpoint.com",
443}},
{inet,[inet],closed}]}}
我无法弄清楚我在这里做错了什么!我正在运行这个版本的 Erlang/OTP 19 [erts-8.0.2]。任何帮助表示赞赏。
【问题讨论】:
-
这个问题的答案有帮助吗:stackoverflow.com/questions/38620111/…?
-
是的!这帮助我修复了它。感谢您的帮助!
-
一般提示:我建议使用
{ok, _} = application:ensure_all_started(ssl)-- 要求 OTP 处理应用程序依赖关系并确保应用程序实际启动。
标签: erlang