Can we use cookies with the httpclient lib for Clojure

I found there is an example to get web data using HttpKit of the following code

(http/get "http://host.com/path")

(def options {:timeout 200             ; ms
              :basic-auth ["user" "pass"]
              :query-params {:param "value" :param2 ["value1" "value2"]}
              :user-agent "User-Agent-string"
              :headers {"X-Header" "Value"}})
(http/get "http://host.com/path" options
          (fn [{:keys [status headers body error]}] ;; asynchronous response handling
            (if error
              (println "Failed, exception is " error)
              (println "Async HTTP GET: " status))))

      

However, is it possible to transfer cookies to it?

Alex's relationship

+3


source to share


1 answer


You can pass cookies to the appropriate header field:

REPL

(require '[org.httpkit.client :as http])
@(http/get "http://localhost:3333" {:headers {"cookie" "testcookie=12345"}})
;; => {:opts {...},
;;     :body #<BytesInputStream BytesInputStream[len=1]>,
;;     :headers {},
;;     :status 200}

      



Console

$ echo -e "HTTP/1.1 200 OK\n\n" | nc -l 3333
GET / HTTP/1.1
Cookie: testcookie=12345
Host: localhost:3333
User-Agent: http-kit/2.0
Accept-Encoding: gzip, deflate
Content-Length: 0

      

+4


source







All Articles