gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 22:53:58 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com