как мне издеваться над почтовым запросом json в кольце?

Я использую перидот - https://github.com/xeqi/peridot для тестирования своего кольцевого приложения, и оно работает нормально, пока Я пытаюсь имитировать почтовый запрос с данными json:

(require '[cheshire.core :as json])
(use 'compojure.core)

(defn json-post [req]
  (if (:body req)
    (json/parse-string (slurp (:body req)))))

(defroutes all-routes
  (POST "/test/json" req  (json-response (json-post req))))

(def app (compojure.handler/site all-routes))

(use 'peridot.core)

(-> (session app)
    (request "/test/json"
             :request-method :post
             :body (java.io.ByteArrayInputStream. (.getBytes "hello" "UTF-8")))

дает IOException: stream closed.

Есть лучший способ сделать это?


person zcaudate    schedule 11.06.2013    source источник


Ответы (1)


(require '[cheshire.core :as json])

(-> (session app)
    (request "/test/json"
             :request-method :post
             :content-type "application/json"
             :body (json/generate-string data))

Не нужно вызывать .getBytes, просто передайте json с параметром :body.

person user1338062    schedule 22.05.2015