如何在httpc: request ()函数发出的http请求中指定客户端授权的用户名/密码??
发布于 2011-11-19 22:24:08
对于digest,您需要做与basic相同的事情,但更多。通常你会在没有auth的情况下访问页面,获取"WWW-Authenticate“头信息,然后使用realm和nonce来生成你的"Authorization”头。http://en.wikipedia.org/wiki/Digest_access_authentication在底部有一个很好的例子。
一般来说,对于大多数用例,HTTPS + Basic即使不是更好,也是足够的。
发布于 2011-11-17 16:48:04
我不认为httpc模块为此提供了便利。然而,它并不难实现(如果我们谈论的是基本身份验证)。毕竟,它只是一个额外的请求头,带有“user:password”对的Base64编码。例如,Tsung's ts_http_common module就是这样做的。
例如,以下是如何使用基本身份验证运行HTTP PUT请求:
auth_header(User, Pass) ->
Encoded = base64:encode_to_string(lists:append([User,":",Pass])),
{"Authorization","Basic " ++ Encoded}.
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). 发布于 2011-11-17 01:24:28
我在文档中看到HTTPOptions持有pass和user:
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()}文档:http://www.erlang.org/doc/man/httpc.html#request-5
https://stackoverflow.com/questions/8148534
复制相似问题