0
Я использую «форму» для отправки данных на мой веб-сервер. передний конец:Я использую koa, koa-router, koa-body в моей программе. Но значение this.reauest.body равно "{}"
<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>
фоновым код, 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"');
Но результат -> this.request.body является {}.
Что я делаю неправильно?
Спасибо! теперь -> {"fields": {"name": "qq", "age": "dd", "wl": "dd"}, "files": {}} – niutrue