如何从 clj-apache-http 向代理服务器进行身份验证?
-
23-09-2019 - |
题
我正在尝试使用 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)
问题是,我的代理(squid)需要身份验证。如何将我的用户名/密码“输入”到该库中?
谢谢!
没有正确的解决方案
其他提示
添加以下到我的头字典的伎俩:
"Proxy-Authorization" (str "Basic "
(base64/encode-str "username:password"))
喜欢Mac说的 - 这也可以用一个滤波器来实现 - 但抢占-基本认证过滤器不会工作,因为它发出的WWW-授权,而不是代理授权的标题
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")))
不隶属于 StackOverflow