handling HTTP POST

Skip to first unread message

Ryan Waters

Mar 22, 2011, 2:32:49 PM3/22/11
to clojure...@googlegroups.com
Hi all,

I'm trying to use compojure and ring to parse POST data and haven't been able to figure out what I'm doing wrong.

I have some client-side clojure that takes a map literal, JSON encodes and URL encodes the result and puts it in an HTTP POST to my compojure/ring setup.

; e.g.
{:a "b"}

When I do the POST, my server-side clojure doesn't parse the data={"a":"b"} but I know it's being sent because I did a packet capture to confirm the POST and "posttestserver.com" successfully parses it (<- handy site - thanks Henry).

Below is my server-side stuff:

- - -

(ns my-ns.core
  (:require [appengine-magic.core :as ae])
  (:use [compojure.core :only [defroutes GET POST]])
  (:use [ring.handler.dump :only [handle-dump]])
  (:require [compojure.route :as route]))

(defroutes my-ns-app-handler
  (POST "/admin/e2f/lineupload" {params :params} handle-dump)
  (route/not-found "Page not found"))

(ae/def-appengine-app threadknow-app #'threadknow-app-handler)

- - -

And here is the result of handle-dump:

- - -

{:remote-addr "",
 :scheme :http,
 #<ResponseWrapper com.google.appengine.api.blobstore.dev.ServeBlobFilter$ResponseWrapper@24bfaa>,
 :servlet #<app_servlet threadknow.app_servlet@1949f78>,
 :request-method :post,
 :query-string nil,
 :route-params {},
 :content-type "application/x-www-form-urlencoded",
 :request #<Request POST /admin/e2f/lineupload HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Language: en-US
Cache-Control: no-cache
Pragma: no-cache
User-Agent: Java/1.6.0_22
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Length: 28

 :uri "/admin/e2f/lineupload",
 :server-name "",
 :params {},
 {"content-length" "28",
  "connection" "keep-alive",
  "accept" "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2",
  "host" "",
  "user-agent" "Java/1.6.0_22",
  "pragma" "no-cache",
  "cache-control" "no-cache",
  "content-language" "en-US",
  "content-type" "application/x-www-form-urlencoded"},
 :content-length 28,
 :server-port 8090,
 :character-encoding nil,
 :body #<Input org.mortbay.jetty.HttpParser$Input@8d3d62>,
 #<AppEngineServletContext ServletContext@1ed7ac{/,file:/home/rwaters/projects/my-ns/war/}>}

- - -

Thank you!

Ryan Waters

Mar 22, 2011, 2:58:03 PM3/22/11
to clojure...@googlegroups.com
My apologies.  I believe this question was answered in the Compojure group under the subject 'Binding POST content' by Bizics on Mar 3, 2011.
Reply all
Reply to author
0 new messages