代码之家  ›  专栏  ›  技术社区  ›  Saeed

如何在erlang的http客户端(httpc)中禁用SSL对等验证

  •  0
  • Saeed  · 技术社区  · 7 年前

    我通过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]).
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Ahmed Omar    7 年前

    虽然禁用验证不是一个好主意,但使用 {ssl, [{verify, verify_none}]} 在选项中。 例子: httpc:request(get, {"https://revoked.badssl.com/", []}, [{ssl, [{verify, verify_none}]}], []).