在邮递员中使用瞬间时,正在剥夺了环境中的第一个字符
在prerequest中使用瞬间:
var yesterday = moment().subtract(1, 'days').format("yyyy-MM-DD");
console.log(yesterday);
var pastDate = yesterday;
pm.environment.set("pastDate", yesterday)
请求正文:
"AccountId": 1,
"StartDate": {{pastDate}}
响应:
{
"errors": {
"StartDate": [
"Unexpected character encountered while parsing value: 2. Path 'StartDate', line 7, position 18.",
"Input string '022-06-26' is not a valid number. Path 'StartDate', line 7, position 27."
]
},
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
}
但是,当查看环境中的值时: PESTDATE:2022-06-26
因此,该变量的第一个字符似乎正在剥离?不确定如何解决这个问题。
Using moment in Prerequest:
var yesterday = moment().subtract(1, 'days').format("yyyy-MM-DD");
console.log(yesterday);
var pastDate = yesterday;
pm.environment.set("pastDate", yesterday)
Request Body:
"AccountId": 1,
"StartDate": {{pastDate}}
Response:
{
"errors": {
"StartDate": [
"Unexpected character encountered while parsing value: 2. Path 'StartDate', line 7, position 18.",
"Input string '022-06-26' is not a valid number. Path 'StartDate', line 7, position 27."
]
},
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
}
However when looking at the value in the Enviroment:
pastDate: 2022-06-26
So it seems the first character of the variable is being stripped? Not sure how to address this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现的分辨率是将VAR内部引号放置,因为JSON需要在引号内收到日期才能操纵值。
The resolution I found was to put the var inside quotes, as JSON needs to recieve dates inside Quote in order to manipulate the value.