这几天不是正在学ring和compojure吗,又复习了一下html,我就想让ring去处理POST请求
(ns form.core
(:require [ring.adapter.jetty :as jetty]
[ring.util.http-response :as resp]
[ring.util.response :refer [redirect]]
[ring.middleware.reload :refer [wrap-reload]]
[compojure.core :refer [routes GET defroutes POST]]
[clojure.java.io :as io]
))
(defroutes app
(GET "/login" request (io/resource "form.html"))
(POST "/form" [fname lname] (str "first name is " fname ", " "last name is " lname)))
(defn -main []
(jetty/run-jetty
(wrap-reload app)
{:port 3000
:join? false}))
这是我在resouce目录下的form.html
<html>
<head>
</head>
<body>
<form action="/form" method="post">
<input type="text" name="fname"><br>
<input type="text" name="lname"><br>
<input type="submit" value="submit"><br>
</body>
</form>
可是我用curl处理的时候,发现
url=localhost:3000/form
curl $url -X POST -d 'fname=hello&lname=world'
得到的响应是
first name is , last name is
路由里怎么接受不到POST的数据啊,求助
我的依赖文件project.clj
(defproject form "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [
[org.clojure/clojure "1.10.0"]
[ring "1.6.3"]
[metosin/ring-http-response "0.9.0"]
[compojure "1.6.1"]
[ring/ring-defaults "0.3.2"]
]
:repositories [["central" "http://maven.aliyun.com/nexus/content/groups/public"]
["clojars" "https://mirrors.tuna.tsinghua.edu.cn/clojars/"]]
:main form.core)
(require 'cemerick.pomegranate.aether)
(cemerick.pomegranate.aether/register-wagon-factory!
"http" #(org.apache.maven.wagon.providers.http.HttpWagon.))