我刚刚在自述文件页面上看到了这个库https://github.com/technomancy/clojure-http-client和这段代码,这就是我想要做的
(res/with-cookies {}
(res/post "http://localhost:3000/login" {} {"user" user "password" password})
(res/get "http://localhost:3000/my-secret-page))但是,该库似乎已被弃用,它建议您改用clj-http库。我只是想知道是否有人知道如何使用这个库来复制这种行为?
目前我只是在做
(post "<site i want to login to>" {:form-params {:username "<my username>" :password "<my password>"}})它返回一个cookie,该cookie具有到经过身份验证的页面的http 302重定向,但是我不知道如何使用经过身份验证的cookie使客户端遵循此重定向。
任何帮助都将不胜感激。
发布于 2012-02-01 05:38:44
仅供参考我解决了这个问题,
(defn login [login-url user pass]
(let [result (client/post "http://my-site.com/login" {:form-params {:username user :password pass}})]
(when (= (:status result) 302)
(:cookies result))))如果登录成功,它将返回cookie映射,然后可以在访问需要您登录的页面时在后续请求中使用该映射,例如
(when-let [cookies (login "http://my-site.com" "my-user" "my-pass")]
(client/get "http://my-site.com/user-page" { :cookies cookies }))
=> <html><head><title>Hello my-user!</titl.......发布于 2011-12-31 20:17:30
我猜你需要显式地使用库中的follow-redirect函数。
https://stackoverflow.com/questions/8684300
复制相似问题