我发现有一个示例可以使用HttpKit获取Web数据代码
(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))))
Run Code Online (Sandbox Code Playgroud)
但是,是否可以将cookie传递给它?
关心亚历克斯
您可以在相应的标题字段中传递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}
Run Code Online (Sandbox Code Playgroud)
安慰
$ 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
Run Code Online (Sandbox Code Playgroud)