Clojure: I am using http-kit to post a request to a server, but it is not working well for me

StackOverflow https://stackoverflow.com/questions/20463919

  •  30-08-2022
  •  | 
  •  

Question

NOTE: I resolved my issue. However, it took a number of incremental changes. If you happen upon this page, feel free to checkout my github below to see how I made this application work.


I am using http-kit to post a request to btc-china. I want to use their trading api. I am able to do this just fine with python, but for some reason I keep getting 401s with clojure and http-kit. I've posted a snippit of code below which may show that I am not using http-kit correctly. In addition to that, here is a github for my full code if you wish to look at that: https://github.com/gilmaso/btc-trading Here are the btc-china api docs: 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))))
Was it helpful?

Solution

quoting from the example on the bttchina site:

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

clojure hash maps are unordered, and you cannot use a clojure hash map literal to provide the input if order is significant

OTHER TIPS

I had very similar problem with bitstamp api. The solution was to replace :query-params with :form-params. Then the parameters are sent in the body. I noticed that in your api you are manually sending then in the body. It looks like using :form-params might help in your case as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top