Using cookies with clj-http.client

463 views
Skip to first unread message

Mike

unread,
Nov 8, 2015, 11:15:17 PM11/8/15
to Clojure
Hello,

I have a web site that uses cookies for authentication.  You logon to a specific URL with your username and password using a POST (which I have working; I get a 200 status back) which should create a cookie; then you use the cookie for all future access to the web site.

I have all of this working on a Windows client using PowerShell.  I'm trying to expand my horizons and start using Clojure for my projects.  So I'm trying to take my working PowerShell script and re-implement it in Clojure.

I read the section in the clj-http.client documentation about using a cookie store and I thought I did it correctly.  Here's what I did:

(require '[clj-http.client :as client])

(def my-cs (clj-http.cookies/cookie-store))
  (client/post login-URL {:body post-data
                          :cookie-store my-cs})
  (client/get customer-list-URL {:cookie-store my-cs})

I was hoping to get a cookie shoved into my-cs and then be able to use it in future accesses.  The client/post call gets a 200 status back, but when I try to look at my-cs it is nil. What am I doing wrong?  TIA!

Jeff Mad

unread,
Nov 10, 2015, 12:18:33 AM11/10/15
to Clojure
I don't see any problem with your code. Try to add :debug true to both of those maps and look at the output.  Ensure that for both URLs share exact same hostname and protocol http/https.  Look at the Set-Cookie header in the POST response and ensure that the path matches the url in the GET. 
Reply all
Reply to author
Forward
0 new messages