Hello,
I'm trying to send a request that includes a cookie with the 4.1.1
version of the HttpClient library. This is my implementation in Clojure:
(defn get [uri & cookies]
(let [client (DefaultHttpClient.)
cookie-store (BasicCookieStore.)]
(doseq [cookie cookies]
(let [cookie (BasicClientCookie. (:name cookie) (:value cookie))]
(.setExpiryDate cookie
(to-date (clj-time/plus (clj-time/now) (clj-time/months 2))))
(.addCookie cookie-store cookie)))
(println (.getCookies (.getCookieStore client)))
(.setCookieStore client cookie-store)
(println (.getCookies (.getCookieStore client)))
(.execute client (HttpGet. uri) (BasicResponseHandler.))))
This is the output of a request to a local page that just prints the
cookies. As you can see, the local code seems to know there is a cookie,
but it never reaches the server:
sp.crawl=> (get "http://localhost:5000/cookies" {:name "foo" :value "baz"})
#<ArrayList []>
#<ArrayList [[version: 0][name: foo][value: baz][domain: null][path: null]
[expiry: Tue Jun 07 14:19:17 CEST 2011]]>
"{}"
I'd really appreciate any pointers as to what I'm doing wrong.
Sincerely,
F.M. (Filip) de Waard / fmw
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]