【问题标题】:Send gzip requests with clj-http使用 clj-http 发送 gzip 请求
【发布时间】:2018-09-21 14:04:14
【问题描述】:

如何使用 dakrone/clj-http 客户端发送压缩请求?到目前为止,我有:

(http/post <<REDACTED>>
           {:body (->> <<REDACTED>>
                       cheshire.core/generate-string
                       .getBytes
                       clj-http.util/gzip)
            :content-type "application/json"
            :content-encoding "gzip"
            :as :json})

但是elasticsearch(我的服务器)给出了500个错误Illegal character ((CTRL-CHAR, code 31)): only regular white space

有什么想法吗?

【问题讨论】:

  • FWIW 根据其test,您的呼叫看起来是正确的。没有 gzip 请求是否有效?
  • 是的,删除 .getBytes、clj-http.util/gzip 和 :content-encoding "gzip" 给了我一个成功的请求。
  • 你在测试中试过了吗?使用clj-http.util/utf8-bytes 明确您想要的编码或将其添加到.getBytes(但随后使用-&gt; 而不是-&gt;&gt;

标签: clojure gzip clj-http


【解决方案1】:

我猜你需要在服务器上启用 HTTP 压缩,例如。 G。在 Elasticsearch 配置中:

http.compression: true 

【讨论】:

  • 我可以使用 curl 发送压缩请求。我认为问题在于我对库的使用或我的 gzipping 代码。
猜你喜欢
  • 2017-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-12
  • 2018-02-07
  • 2014-12-24
  • 2011-09-06
  • 1970-01-01
相关资源
最近更新 更多