gpt4 book ai didi

cookies - 我们可以将 cookie 与 http 客户端库一起用于 Clojure

转载 作者:行者123 更新时间:2023-12-05 01:02:25 24 4
gpt4 key购买 nike

我发现有一个示例可以使用以下代码使用 HttpKit 获取网络数据

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

但是,是否也可以将 cookie 传递给它?

问候
亚历克斯

最佳答案

您可以在相应的 header 字段中传递 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

关于cookies - 我们可以将 cookie 与 http 客户端库一起用于 Clojure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26646753/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com