【发布时间】:2021-05-08 23:39:19
【问题描述】:
我是 Node 新手,在使用 POST 功能时遇到问题。 我有一个简单的网站,其中有以下几行:
app.get('/sign',(req,res)=>{
res.sendFile(path.join(__dirname, 'static', 'index.html'));
});
app.post('/sign', (req,res)=>{
res.send("Success!")
});
get 请求工作得很好,但是当我将表单中的数据发回时,我没有收到成功消息,而是收到了Cannot POST /。
当使用 app.get('/', etc.) 从“/”目录执行相同操作时
它工作正常。
这是“index.html”文件的内容:
<form action = '/' method='POST' id="form">
<div class="form-group">
<label for="emal">Email address</label>
<input type="email" class="form-control" name="email">
</div>
<div class="form-group">
<label for="pwd">Password</label>
<input type="password" class="form-control" name="password">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
【问题讨论】:
-
您能否分享您用于“将表单中的数据发回”的代码?您似乎没有发布到正确的端点。
标签: html node.js http web post