Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure 将响应主体的字符集从UTF-8更改为CP1251_Clojure_Http Kit - Fatal编程技术网

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