更新时间:2023-11-07 17:15:40
You can use ring.util.request/body-string
to get the request body as a String.
(body-string request)
您需要记住, InputStream
只能被读取一次,因此您可能更喜欢将原来的:body
替换为读取的 String
您以后可以再次访问它:
You need to remember that InputStream
can be read only once so you might prefer replace the original :body
with the read String
instead so you can later access it again:
(defn wrap-body-string [handler]
(fn [request]
(let [body-str (ring.util.request/body-string request)]
(handler (assoc request :body (java.io.StringReader. body-str))))))
并添加中间件以包装处理程序:
And add your middleware to wrap your handler:
(def app
(wrap-body-string handler))