2011-11-16 67 views

回答

1

對於消化,你需要做同樣的事情,基本的,但更是這樣。一般而言,您將在未經身份驗證的情況下訪問該頁面,獲取「WWW-Authenticate」標題信息,然後使用領域和隨機數生成您的「授權」標題。 http://en.wikipedia.org/wiki/Digest_access_authentication在底部有一個體面的例子。

對於大多數使用情況來說,HTTPS + Basic通常是足夠的,如果不是更好的話。

2

我在HTTPOptions持有通和用戶文檔,請參閱:

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

+0

您可能正在談論代理授權,它由屬性{proxy_auth,{userstring(),passwordstring()}}指定。儘管如此,它並沒有解決我的問題。 – mkorszun

9

我不認爲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). 
+0

Thx,它完成這項工作。摘要怎麼樣?似乎inets也不支持它。 – mkorszun

0

嘗試使用ibrowse,支持,我一直在使用!​​

相關問題