Tyl*_*ler 2 node.js express angularjs
我正在使用angularjs发送POST,如下所示:
$http.post("/mypath", { data: "foobar" })
Run Code Online (Sandbox Code Playgroud)
在nodejs(expressjs)中,我试图像这样拾取它:
app.post "/mypath", (req, res) ->
console.log "req.body: ", req.body
res.end()
Run Code Online (Sandbox Code Playgroud)
我尝试了各种不同的化身(body: "foobar",等等),但我不断req.body: undefined
有没有一种简单的方法可以读取节点/表达式中的有效负载?
要从Node中的POST获取数据,您需要使用主体解析器。例如:
var bodyParser = require('body-parser');
//use bodyParser() to let us get the data from a POST
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1227 次 |
| 最近记录: |