我一直在烦恼地找到只解析发送的JSON的例子 . 我试图找到一个POST来自表单的示例 .
<form class="form-horizontal" role="form" action="/" method="post">
<input type="text" class="form-control" name="email" placeholder="your@email.here">
<input type="text" class="form-control" name="password" placeholder="password">
<button type="submit" class="btn btn-default">Sign in</button>
</form>
如你所见,我有字段 email
和 password
. 我正在使用 koa-router
,它拥有快速样式路由,但这不起作用:
.post('/', function* () {
console.log(this.body.email); // <--- undefined
console.log(this.body.password);
})
1 回答
您将要使用如下所示的库:
https://github.com/cojs/co-body