ring: read body of a http request as string

后端 未结 2 1674
情深已故
情深已故 2021-01-19 00:50

When handling a http request inside a ring server, the body of the request-data is stored in the request-hashmap in the key :body. For instance as followed:

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-19 01:05

    The :body of ring request must be an instance of java.io.InputStream. So you can use reader + slurp to get a string out.

    (defn is->str [is]
      (let [rdr (clojure.java.io/reader is)]
        (slurp rdr)))
    

    Usage: (is->str (:body request))

提交回复
热议问题