2014-10-30 38 views
3

,我發現有一個例子讓與HttpKit網絡數據下面的代碼我們可否與HttpClient的lib中的cookie進行Clojure的

(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)))) 

但是,是有可能的餅乾傳遞給它呢?

問候 亞歷

回答

4

你可以在相應的報頭字段傳遞的cookie:

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} 

控制檯

$ 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 
相關問題