Clojure:我正在使用 http-kit 向服务器发布请求,但它对我来说效果不佳

标签 clojure http-kit

注意:我解决了我的问题。但是,它进行了一些渐进式更改。如果您偶然发现此页面,请随时查看下面我的 github 以了解我如何使该应用程序工作。

我正在使用 http-kit 向 btc-china 发布请求。我想使用他们的交易 API。我可以用 python 很好地做到这一点,但由于某种原因,我一直在使用 clojure 和 http-kit 获得 401。我在下面发布了一段代码,这可能表明我没有正确使用 http-kit。除此之外,如果您想查看我的完整代码,这里有一个 github:https://github.com/gilmaso/btc-trading
以下是 btc-china api 文档:http://btcchina.org/api-trade-documentation-en

(def options {:timeout 2000 ; ms
          :query-params (sorted-map :tonce tonce
                                    :accesskey access-key
                                    :requestmethod request-method
                                    :id tonce
                                    :method method
                                    :params "")
          :headers {"Authorization" auth-string
                    "Json-Rpc-Tonce" tonce}})

(client/post (str "https://" base-url) options
      (fn [{:keys [status headers body error]}] ;; asynchronous handle response
        (if error
          (println "Failed, exception is " error)
          (println "Async HTTP GET: " status))))

最佳答案

引自 example on the bttchina site :

# The order of params is critical for calculating a correct hash

clojure 哈希映射是无序的,如果顺序很重要,则不能使用 clojure 哈希映射文字来提供输入

关于Clojure:我正在使用 http-kit 向服务器发布请求,但它对我来说效果不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20463919/

相关文章:

jar - clojure/lein : Can I specify a project file for lein other than project. clj?

networking - 如何在 Clojure (/Java) 中稳健地发出大量并发 HTTPS 请求

clojure - 环防伪中间件是否可以有条件应用?

clojure - 这是 Clojure 惯用的吗?

file - 如何在 Clojure 中将整个二进制文件(Nippy)读入字节数组?

clojure - 如何判断http-kit客户端回调超时?

clojure - 如何简化 Compojure 路线?

Clojure Web(HttpKit、Manifold)与 Elixir/Phoenix

performance - 提高 ClojureScript 程序的性能

Clojure Defn 在显示正确答案后返回空括号