const BodyParser = require('body-parser')
const Config = require('../config/environment');
const Express = require("express");
const App = Express();
App.use(BodyParser.json({type: '/', limit: '50mb'}));
App.use(BodyParser.urlencoded({extended: false}));
App.listen(3000, () => {Response.logger('Api running on port 3000.');});
App.post("/signup", (req, res, next) =>
{
consoleAlert('SIGNUP', false);
console.log(req);
Account.signup(req.params).then(
function(results) {response(results, res, 'SIGNUP');},
function(error) {response(error, res, 'SIGNUP');});
});
因此,当我打印出要求时,正文始终为空,其中包含表单数据
答案 0 :(得分:0)
从头开始编写-看来可行:
服务器:
//app.js
const express = require('express');
const bodyParser = require('body-parser');
let app = express();
app.use(bodyParser.urlencoded({extended: false}));
app.post('/', function(req, res, next) {
console.log(req.body);
});
app.listen(3022);
客户端:从命令行调用curl发送发送表单数据(默认为application / x-www-form-urlencoded),我的节点服务器IP为10.10.1.40:
curl -d "param1=value1¶m2=value2" -X POST http://10.10.1.40:3022/