【发布时间】:2014-07-24 01:03:22
【问题描述】:
我正在尝试让服务器处理 PUT 请求。但无济于事。客户端在提交表单后不断收到“Cannot POST /”消息。 我正在使用 Express 4.x。
请注意,如果我在路由中将“put”更改为“post”,请求会得到很好的处理...
如何让我的服务器处理“PUT”请求?
服务器:
var express = require("express");
var bodyParser = require("body-parser");
var methodOverride = require("method-override");
var app = express();
app.use(bodyParser());
app.use(methodOverride());
app.get("/",function(req,res){
res.render("index.ejs");
console.log("GET received.");
});
app.put("/",function(req,res){
console.log("PUT received: " + req.body.userName + " - " + req.body.password);
});
app.listen(1337);
console.log("Listening on 1337.");
客户
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
</head>
<body>
<form action="/" method="post">
First
<input type="text" name="first">
Last
<input type="text" name="last">
<input type="hidden" name="_method" value="put">
<button type="submit">Submit</button>
</form>
</body>
</html>
【问题讨论】:
标签: javascript node.js express connect