Read the POST raw data of a request, but finds it empty.

142 views
Skip to first unread message

actioncao

unread,
Mar 2, 2014, 2:56:24 AM3/2/14
to comp...@googlegroups.com
lein new compojure hello-world

(defn post_body [body]
  (println body))

(defroutes app-routes
  (POST "/wx_dmsj/" [body] (post_body body)))

In the compojure document:
In a request, the value for :body is an InputStream. InputStream is mutable and can only ever be read once. Anything that tries to read the InputStream after it has already been read will fail to do so. If you find the value for :body empty when it shouldn't be, the most likely cause is some other middleware higher in the stack reading the InputStream before it gets to you.

How should I do?



James Reeves

unread,
Mar 2, 2014, 6:43:32 AM3/2/14
to Compojure
You're using the syntax to look for a form parameter called "body", not the body of the request.

If you want all the parameters in the body, use:

(POST "/wx_dmsj" [& params] ...)

Or:

(POST "/wx_dmsj" {params :params} ...)

If you want the literal body itself:

(POST "/wx_dmsj" {body :body} ...)

If you want the whole request:

(POST "/wx_dmsj" request ...)

- James


--
You received this message because you are subscribed to the Google Groups "Compojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to compojure+...@googlegroups.com.
To post to this group, send email to comp...@googlegroups.com.
Visit this group at http://groups.google.com/group/compojure.
For more options, visit https://groups.google.com/groups/opt_out.

actioncao

unread,
Mar 2, 2014, 11:06:26 AM3/2/14
to comp...@googlegroups.com, ja...@booleanknot.com
Tinks!

在 2014年3月2日星期日UTC+8下午7时43分32秒,James Reeves写道:
Reply all
Reply to author
Forward
0 new messages