Clojure 将响应主体的字符集从UTF-8更改为CP1251
我评估以下代码Clojure 将响应主体的字符集从UTF-8更改为CP1251,clojure,http-kit,Clojure,Http Kit,我评估以下代码 (org.httpkit.client/get "http://localhost:81" #(clojure.pprint/pprint (.getBytes (:body %)))) 它打印 [-17, -65, -67, -17, -65, -67] 如果index.html在CP1251中,并且 [-48, -80, -48, -79, -48, -78] 如果同一文档采用UTF-8格式 俄文index.html内容为 абв
(org.httpkit.client/get "http://localhost:81"
#(clojure.pprint/pprint (.getBytes (:body %))))
它打印
[-17, -65, -67, -17, -65, -67]
如果index.html在CP1251中,并且
[-48, -80, -48, -79, -48, -78]
如果同一文档采用UTF-8格式
俄文index.html内容为
абв
http工具包将响应体作为UTF-8编码的字符串对象返回,但它不考虑HTML文档的实际字符集。这会在体内产生垃圾,就像
"<html>�����</html>"
”�����"
如何使org.httpkit.client/get成为文档的字符集?通过使用org.httpkit.client.request和特定选项,可以获取正文的原始字节 如果文档采用CP1251编码,则以下代码将打印正确的正文内容
(org.httpkit.client/request {:url "http://localhost:81" :as :byte-array}
#(println (String. (:body %) "cp1251")))