如何在 erlang 的 http 客户端(httpc)中禁用 SSL 对等验证
How can disable SSL peer verification in http client (httpc) in erlang
我通过 http 客户端发送了一个 restfull api 请求,但我收到以下错误:
{error,{failed_connect,[{to_address,{"https://example.com",443}},
{inet,[inet],{tls_alert,"record overflow"}}]}}
我发现 SSL 对等验证造成了这个问题。我怎样才能禁用它?
我的代码:
test() ->
inets:start(),
ssl:start(),
RequestBody = "",
Request = {"https://example.com", [{"X-API-CODE",""}, {"Accept","application/json"}, {"access-token",""}], "application/json", RequestBody},
{ok, {_, _, ResponseBody}} = httpc:request(post, Request, [], []),
io:format("~st", [ResponseBody]).
虽然禁用验证不是一个好主意,但可以通过在选项中使用 {ssl, [{verify, verify_none}]}
来实现。
例子:
httpc:request(get, {"https://revoked.badssl.com/", []}, [{ssl, [{verify, verify_none}]}], []).
我通过 http 客户端发送了一个 restfull api 请求,但我收到以下错误:
{error,{failed_connect,[{to_address,{"https://example.com",443}},
{inet,[inet],{tls_alert,"record overflow"}}]}}
我发现 SSL 对等验证造成了这个问题。我怎样才能禁用它?
我的代码:
test() ->
inets:start(),
ssl:start(),
RequestBody = "",
Request = {"https://example.com", [{"X-API-CODE",""}, {"Accept","application/json"}, {"access-token",""}], "application/json", RequestBody},
{ok, {_, _, ResponseBody}} = httpc:request(post, Request, [], []),
io:format("~st", [ResponseBody]).
虽然禁用验证不是一个好主意,但可以通过在选项中使用 {ssl, [{verify, verify_none}]}
来实现。
例子:
httpc:request(get, {"https://revoked.badssl.com/", []}, [{ssl, [{verify, verify_none}]}], []).