Inets http客户端+授权


哇塞
2025-03-20 06:20:59 (1天前)
  1. 我该如何指定客户端的用户/密码


授权
</跨度>
在http请求http:request()函数??
锟斤拷

5 条回复
  1. 0# 早岁那知世事艰 | 2019-08-31 10-32



    对于摘要,你需要做与基本相同的事情,但更重要的是。通常,您将在没有auth的情况下点击页面,获取“WWW-Authenticate”标题信息,然后使用领域和现时生成“授权”标题。

    http://en.wikipedia.org/wiki/Digest_access_authentication

    在底部有一个很好的例子。



    通常,对于大多数用例,HTTPS + Basic即使不是更好,也足够了。


  2. 1# 薄情 | 2019-08-31 10-32



    我不认为

    httpc

    模块为此提供便利。
    然而,实施并不困难(如果我们谈论基本认证)。毕竟它只是一个额外的请求标题,其中’user:password’对Base64编码。
    例如

    Tsung的ts_http_common模块

    可以。



    例如,以下是如何使用基本身份验证运行HTTP PUT请求:




    1. auth_header(User, Pass) ->
      Encoded = base64:encode_to_string(lists:append([User,”:”,Pass])),
      {“Authorization”,”Basic ++ Encoded}.

    2. put_request(Url, User, Pass, Body) ->
      ContentType = text/json”,
      Headers = [auth_header(User, Pass), {“Content-Type”,ContentType}],
      Options = [{body_format,binary}],
      httpc:request(put, {Url, Headers, ContentType, Body}, [], Options).

    3. </code>

  3. 2# 大黑骡子王 | 2019-08-31 10-32



    我在doc中看到HTTPOptions持有pass和user:




    1. HTTPOptions = http_options()
      http_options() = [http_option()]
      http_option() = {timeout, timeout()} | {connect_timeout, timeout()} | {ssl, ssloptions()} | {ossl, ssloptions()} | {essl, ssloptions()} | {autoredirect, boolean()} | {proxy_auth, {userstring(), passwordstring()}} | {version, http_version()} | {relaxed, boolean()} | {url_encode, boolean()}

    2. </code>


    文档:

    http://www.erlang.org/doc/man/httpc.html#request-5


  4. 3# 满目山河 | 2019-08-31 10-32



    尝试使用ibrowse,支持并且我一直在使用它!

    https://github.com/cmullaparthi/ibrowse


登录 后才能参与评论