KOA POST 方法未发送正文
KOA POST method is not sending body
我有一个基于 KOA 的 NodeJS 应用程序,其中很简单:
html + 控制器
以下是我的html
<!DOCTYPE html>
<html>
<body>
<form method="POST" action="/admin/login">
<div>
<div>
Username
<input id="username_text" autocorrect="off" autocapitalize="none">
</div>
<div>
Password
<input id="password_text" autocorrect="off" autocapitalize="none" type="password">
</div>
</div>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
在我的控制器端,我有以下代码来获取用户名和密码:
let fn_loginPost = async function (ctx, next) {
let body = ctx.request.body;
let user_name = body.username_text;
let password = body.password_text;
然而,我发现 body 对象的值为空 {}
我已经在 app.js 中以正确的顺序使用了 bodyParser:
app.use(bodyParser);
app.use(router.routes());
请帮忙。
您的 <input>
字段需要 name=""
属性,而不是 id=""
我有一个基于 KOA 的 NodeJS 应用程序,其中很简单: html + 控制器
以下是我的html
<!DOCTYPE html>
<html>
<body>
<form method="POST" action="/admin/login">
<div>
<div>
Username
<input id="username_text" autocorrect="off" autocapitalize="none">
</div>
<div>
Password
<input id="password_text" autocorrect="off" autocapitalize="none" type="password">
</div>
</div>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
在我的控制器端,我有以下代码来获取用户名和密码:
let fn_loginPost = async function (ctx, next) {
let body = ctx.request.body;
let user_name = body.username_text;
let password = body.password_text;
然而,我发现 body 对象的值为空 {}
我已经在 app.js 中以正确的顺序使用了 bodyParser:
app.use(bodyParser);
app.use(router.routes());
请帮忙。
您的 <input>
字段需要 name=""
属性,而不是 id=""