【问题标题】:jmeter returns undefined as outputjmeter 返回 undefined 作为输出
【发布时间】:2016-10-01 19:02:36
【问题描述】:

我通过以下方式将数据从我的 Angular JS 发送到我的节点 API:

Angular 内部:

$http({

    method : "POST",
        url : '/add',

    data : {
            "a" : $scope.a,
                "b" : $scope.b
               }

}).success(function(data) {

    $scope.result = data.result;


}).error(function(error) {

    $scope.result = 'Invalid data...';

});

在我的 nodejs API 定义中:

exports.execute = function(req, res){

    var a = req.body.a;
    var b = req.body.b;

    var result;

    result = Number(a) + Number(b);

    var json_responses;

    console.log('from api add');
    console.log((a));
    console.log(b);
    console.log(result.toString());

    json_responses = {"result" : result.toString()};

    res.send(json_responses);

};

当我从浏览器输入值时,API 和角度工作正常,实际值打印在控制台上。

但是,当我尝试使用 POSTMAN 发布数据或使用数据进行 JMETER 负载平衡测试时,控制台会将数据打印为 "undefined"。 我尝试定义数据的方式是:

data={
   a : 100,
   b : 100
}


data={
   "a" : "100",
   "b" : "100"
}

data={
   "a" : 100,
   "b" : 100
}

我错过了什么??

【问题讨论】:

    标签: angularjs node.js jmeter postman


    【解决方案1】:

    您需要设置标头Content-Type,并且值必须是application/json才能在req.body中接受,而AnguarJS发送的Content-Type默认为application/json

    【讨论】:

    • 邮递员呢?我尝试在 HTTP 标头管理器中添加内容类型,但它停止在控制台的请求中显示任何值。请指导。
    • 应该可以,你可以试试res.json(json_responses);
    • 我只需要设置内容类型。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-18
    • 1970-01-01
    • 1970-01-01
    • 2021-09-25
    • 2018-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多