json - 如何使用 'loadtest' nodejs 模块加载测试 post API?

标签 json node.js post load-testing stress-testing

我正在使用 loadtest Nodejs 模块来测试 NodeJS 脚本中 API 的压力测试。 Get 调用语法有效,但 post 调用无效。代码如下。

function optionsObject() {
  return { 
  url: 'http://localhost:3000/api/v2/signup',
  maxRequests: 1,
  concurrency: 1,
  method: 'POST',
  contentType: 'applicaton/json',
  body: {
     password: 'test',
     email: 'testobject_1@signup2.com',
     name: 'kPYgJ6Rg5wnExt8hTXQIHDn2LaCMsytjhQzp' 
        }
   }

}

loadtest.loadTest(optionsObject(), function (error, result) {
            if (error) {
             console.log('Got an error: %s', error);
            } else {
             console.log(result);
              }
            });

            Results:
                {
                 totalRequests: 1,
                 totalErrors: 1,
                 totalTimeSeconds: 0.025545716,
                 rps: 39,
                 meanLatencyMs: 20,
                 maxLatencyMs: 20,
                 percentiles: { '50': 20, '90': 20, '95': 20, '99': 20 },
                 errorCodes: { '400': 1 } 
                 }

任何人都可以帮助我解决为什么我收到错误请求错误 400 吗?

最佳答案

Content-Type 的声明中有一个拼写错误。 (第二个 i 丢失了。)

使用

contentType: 'application/json',

相反,它就可以工作。

关于json - 如何使用 'loadtest' nodejs 模块加载测试 post API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30365569/

相关文章:

json - 如何在 D 中使用 JSON 数据发出 http POST 请求

json - 在 Node 中将 JSON 漂亮地打印到文件中

javascript - 使用bunyan记录器登录nodejs,将DEBUG、INFO、ERROR打印到同一文件

node.js - Protractor JS 预处理器

php - 如何防止 jQuery post 处理程序被恶意使用?

php - 功能性重定向的 HTTP 状态

javascript - 如何从 Facebook 群组获取我所有帖子的列表

javascript - 在 Node.js 中获取错误的日期

c# - 将 XML 转换为动态 C# 对象

javascript - 类构造函数中选项对象的默认值