hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Filip de Waard <...@vix.io>
Subject problem sending a request with cookies
Date Thu, 07 Apr 2011 12:54:39 GMT

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.


F.M. (Filip) de Waard / fmw

To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org

View raw message