postman - Postman Monitor 未能通过本地所有测试的请求
问题描述
我写了一个简单的 Postman 集合,其中包含一些针对我用来计算基于游戏的东西的 API 的请求。
在本地,请求按预期工作。在监视器上,他们似乎没有发送任何尸体。
我确实在标题中手动将内容类型设置为 application/json。我的请求有一个 JSON 正文。
您可以在https://ffxiv-dps.herokuapp.com/dps 使用以下正文测试请求 API :
{
"job": "PLD",
"stats": {
"WD": 109,
"Strength": 2735,
"DirectHit": 785,
"CriticalHit": 2625,
"Determination": 1075,
"SkillSpeed": 1133,
"Vitality": 3754,
"Tenacity": 852,
"Defense": 5737
}
}
我的测试如下所示:
pm.test("Response is ok", function() {
pm.response.to.have.status(200);
});
pm.test("Response Body has JSON with data", function() {
pm.response.to.have.jsonBody("StatisticIntervals");
pm.response.to.have.jsonBody("DamagePerSecond");
});
pm.test("Response Body has valid JSON Data", function() {
var responseJSON = pm.response.json();
pm.expect(responseJSON.StatisticIntervals.CriticalHit).to.be.ok;
console.log("Critical Hit is OK");
pm.expect(responseJSON.StatisticIntervals.DirectHit).to.be.ok;
console.log("Direct Hit is OK");
pm.expect(responseJSON.StatisticIntervals.Determination).to.be.ok;
console.log("Determination is OK");
pm.expect(responseJSON.StatisticIntervals.SkillSpeed).to.be.ok;
console.log("Skill Speed is OK");
pm.expect(responseJSON.StatisticIntervals.Tenacity).to.be.ok;
console.log("Tenacity is OK");
pm.expect(responseJSON.StatisticIntervals.Defense).to.be.ok;
console.log("Defense is OK");
pm.expect(responseJSON.DamagePerSecond).to.be.ok;
console.log("DPS is OK");
})
请注意,此 Web 服务器在 Heroku dyno 上运行,因此可能需要一些时间才能摆脱空闲状态。
有了它,您应该能够重现问题 - 它可以在本地工作,但不能使用 Monitor 工作(我的 API 将响应 400: Bad Request - 这很好,但不是这个请求应该产生的结果)。
解决方案
运行以下请求:
curl --location --request GET "https://ffxiv-dps.herokuapp.com/dps" \
--header "Content-Type: application/json" \
--data "{
\"job\": \"PLD\",
\"stats\": {
\"WD\": 109,
\"Strength\": 2735,
\"DirectHit\": 785,
\"CriticalHit\": 2625,
\"Determination\": 1075,
\"SkillSpeed\": 1133,
\"Vitality\": 3754,
\"Tenacity\": 852,
\"Defense\": 5737
}
}"
在本地以及在监视器上都会产生相同的结果,即所有测试都通过了。
推荐阅读
- python - Python:如何从请求标头中提取值?
- python-3.x - 运行 keras model.fit_generator 后需要帮助纠正错误
- firefox - Heroku 托管页面抛出错误 - navigator.mediaDevices 未定义
- python-3.x - python中连接失败时如何重新连接到websocket
- php - AngularJS 反序列化 PHP 字符串
- python - 多处理问题
- filesystems - 如何在 elixir 中创建相同的目录名称?
- java - OrdImage LoadFromFile 异常
- mysql - 什么是点?
- python-3.x - imaplib 的 Internaldate2tuple 期望什么输入?