I use "form" to send data to my webserver. front-end:
<form action="http://localhost:3131/users" method="POST" enctype="multipart/form-data" target="_blank">
<fieldset>
<label for="name">Name:</label>
<input type="text" id="name" name="name"/>
</fieldset>
<fieldset>
<label for="age">Age:</label>
<input type="text" id="age" name="age"/>
</fieldset>
<fieldset>
<label for="wl">Wl:</label>
<input type="text" id="wl" name="wl"/>
</fieldset>
<fieldset>
<input type="submit" value="Submit"/>
</fieldset>
</form>
back-end code, Github link:
var app = require('koa')(),
router = require('koa-router')(),
koaBody = require('koa-body')();
router.post('/users', koaBody,
function *(next) {
console.log(this.request.body);
// => POST body
this.body = JSON.stringify(this.request.body);
}
);
app.use(router.routes());
app.listen(3131);
console.log('curl -i http://localhost:3131/users -d "name=test"');
But the result is --> this.request.body is {}.
What am i doing wrong?