在nodejs request.body是未定义的

时间:2017-01-19 13:45:27

标签: node.js http-post

当我从angularjs发送一个post请求到nodejs request.body未定义,但是当通过get方法

发送时我能够接收到值

我的angularjs代码

app.controller('create_company', function($scope,$http) {
$scope.save = function() {
    console.log($scope.company);
var temp=$scope.company;
        $http({
            url: "http://localhost:4000/comp/signUp",
            method: "POST",
            data: temp
        }).success(function(data, status, headers, config) {
            $scope.data = data;
        }).error(function(data, status, headers, config) {
            $scope.status = status;
        });

    }

我的nodejs代码:

var express = require('express');
      var compRouter = express.Router();
      var router = function () {
        compRouter.route('/signUp')
            .post(function (request, response) {
              console.log(request.body);


            });


        return compRouter;
  }

1 个答案:

答案 0 :(得分:0)

使用正文解析中间件。你可以检查; https://github.com/expressjs/body-parser