在邮递员中使用瞬间时,正在剥夺了环境中的第一个字符

发布于 2025-02-11 01:16:31 字数 822 浏览 2 评论 0原文

在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

芯好空 2025-02-18 01:16:31

我发现的分辨率是将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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文