【问题标题】:How do I do an HTTPS request with Erlang?如何使用 Erlang 进行 HTTPS 请求?
【发布时间】:2011-02-22 14:41:05
【问题描述】:

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

【问题讨论】:

  • “它不工作?”发布您的错误!发布您的代码!

标签: ssl https erlang erlang-otp inets


【解决方案1】:

这对我来说很好用:

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

【讨论】:

    【解决方案2】:

    这对我有用:

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

    【讨论】:

      【解决方案3】:

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

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

      否则会有警告:"Authenticity is not established by certificate path validation"

      更多选项见:https://www.erlang.org/doc/man/httpc.html#request-4

      【讨论】:

        猜你喜欢
        • 2017-07-28
        • 2015-10-31
        • 2012-11-15
        • 2011-12-23
        • 1970-01-01
        • 2014-10-10
        • 2011-08-22
        • 2018-11-08
        • 2019-06-26
        相关资源
        最近更新 更多