当我尝试在使用Compojure模板创建的Clojure Webapp项目中使用POST方法时,得到了“ 无效的防伪令牌 ”。
我进行了研究,Ring中间件为来自其他站点的经过身份验证的请求创建了CSRF(跨站点请求表单)令牌(以使用已经登录并访问不允许访问的页面的其他人的凭据)。
这些令牌是默认的,我们需要在WebApp周围使用ring.middleware的wrap-params。无法到达任何地方。请帮忙 !!如何摆脱无效的防伪令牌。
我的handler.clj文件是:
(ns jsonparser-webapp.handler
(:require [compojure.core :refer :all]
[compojure.route :as route]
[jsonparser-webapp.views :as views])
(:use [ring.middleware.params :only [wrap-params]])
(defroutes app-routes
(GET "/"
[]
(views/home-page))
(GET "/goto"
[]
(views/goto))
(POST "/posted"
{params :params}
(views/posted params))
(route/not-found "Not Found"))
(def app
(wrap-params app-routes site-defaults))
Run Code Online (Sandbox Code Playgroud)
我的views.clj文件是
(ns jsonparser-webapp.views
(:require [hiccup.page :as hic-p]
[hiccup.form :as hf]))
(defn gen-page-head
[title]
[:head
[:title title]])
(defn home-page
[]
(hic-p/html5
(gen-page-head "Json Parser Home.")
[:h1 "Welcome."]
[:p "Json Web App."] …Run Code Online (Sandbox Code Playgroud)