Compojure POST 请求中缺少表单参数 [英] Missing form parameters in Compojure POST request

查看:18
本文介绍了Compojure POST 请求中缺少表单参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在获取以下 Compojure 示例中的表单参数时遇到问题:

I'm having problems getting the form parameters in the following Compojure example:

(ns hello-world
  (:use compojure.core, ring.adapter.jetty)
  (:require [compojure.route :as route]))

(defn view-form []
(str "<html><head></head><body>"
   "<form method="post">"
   "Title <input type="text" name="title"/>"
   "<input type="submit"/>"
   "</form></body></html>"))

(defroutes main-routes
  (GET "/" [] "Hello World")
  (GET "/new" [] (view-form))
  (POST "/new" {params :params} (prn "params:" params))
  (route/not-found "Not Found"))

(run-jetty main-routes {:port 8088})

提交表单时输出总是

params: {}

我不明白为什么标题参数不在 params 映射中.

and I can't figure out why the title parameter is not in the params map.

我使用的是 Compojure 0.6.2.

I'm using Compojure 0.6.2.

推荐答案

你有没有考虑到这一点:

Have you taken into account this:

从 0.6.0 版本开始,Compojure 不再向路由添加默认中间件.这意味着您必须将 wrap-params 和 wrap-cookies 中间件显式添加到您的路由中.

As of version 0.6.0, Compojure no longer adds default middleware to routes. This means you must explicitly add the wrap-params and wrap-cookies middleware to your routes.

来源:https://github.com/weavejester/compojure

我用我当前的设置尝试了你的例子,它奏效了.我包含了以下内容:require [compojure.handler :as handler](handler/api routes).

I tried your example with my current setup and it worked. I have included the following: require [compojure.handler :as handler] and (handler/api routes).

这篇关于Compojure POST 请求中缺少表单参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆