【发布时间】:2015-06-02 01:22:08
【问题描述】:
我编写了简单的客户端-服务器应用程序,参考“ClojureScript:启动并运行”。
https://github.com/phaendal/clojure-simple-client-server
如下服务器代码所示,/text 将请求和正文打印到控制台并从(slurp (:body req)) 返回正文。
但如果project.clj 中的:auto-refresh? 设置为true,(slurp (:body req)) 将返回空字符串而不是发送的值。
为什么它返回空?以及如何通过自动刷新获取请求正文?
(ns client-server.server
(:gen-class)
(:require [compojure.route :as route]
[compojure.core :as compojure]
[ring.util.response :as response]))
(defn simple-print [req]
(let [body (slurp (:body req) :encoding "utf-8")]
(println req)
(println (str "slurped: " body))
body))
(compojure/defroutes app
(compojure/POST "/text" request (simple-print request))
(compojure/GET "/" request
(-> "public/index.html"
(response/resource-response)
(response/content-type "text/html")
(response/charset "utf-8")))
(route/resources "/"))
【问题讨论】:
标签: clojure leiningen ring compojure