2

我正在尝试使用http://github.com/rnewman/clj-apache-http开始运行

(http/get (java.net.URI. url)
        :headers {"User-Agent" user-agent}
        :parameters (http/map->params
                 {:default-proxy (http/http-host :host "localhost"
                                 :port 8888)})
        :as :string)

问题是,我的代理(鱿鱼)需要身份验证。如何将我的用户名/密码“输入”到这个库中?

谢谢!

4

2 回答 2

2

Adding the following to my headers dictionary did the trick:

"Proxy-Authorization" (str "Basic "
                             (base64/encode-str "username:password"))

Like Mac said -- this could also be implemented with a filter -- but preemptive-basic-auth-filter won't work because it sends the headers for WWW-Authorization instead of Proxy-Authorization.

于 2010-03-30T20:56:18.750 回答
0

clj-apache-http 有一个 preemptive-basic-auth-filter 可供您使用。它支持这种形式的组合用户名/密码字符串“名称:密码”。该功能的使用没有很好的文档记录,但可以在此处找到。示例(未测试):

(http/get (java.net.URI. url)
    :headers {"User-Agent" user-agent}
    :parameters (http/map->params
             {:default-proxy (http/http-host :host "localhost"
                             :port 8888)})
    :as :string
    :filters ((preemptive-basic-auth-filter "name:password")))
于 2010-03-30T05:53:56.563 回答