如何在请求主体中使用{{$ randomint}}并将其保存在环境中

发布于 2025-02-04 02:06:29 字数 339 浏览 3 评论 0原文

我正在尝试使用{{$ randomInt}}生成一个随机数,并在预定脚本中编写此脚本以获取并在环境中设置值

let rand_int = pm.variables.replaceIn('{{$randomInt}}')
pm.environment.set("rand_int", rand_int)

,但我想直接在身体中使用{{$ randomint}}请求主体直接在环境中的值。有什么办法吗?

假设这是我的要求。当我发送请求时,我想在环境中自动设置该随机值。

{
   "gårdsnummer": {{$randomInt}}
}

I am trying to generate a random number using {{$randomInt}} and writing this script in pre-request script to get and set the value in an environment

let rand_int = pm.variables.replaceIn('{{$randomInt}}')
pm.environment.set("rand_int", rand_int)

But I want to use {{$randomInt}} directly in the body and store the value directly in the environment from the request body. Is there any way to do it?

Suppose this is my request body. When I send the request I want to auto-set that random value in the environment.

{
   "gårdsnummer": {{$randomInt}}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

放飞的风筝 2025-02-11 02:06:29

当您在请求正文中使用环境变量时,您不需要或不应该使用$。以下应该有效:

{
    "gårdsnummer": {{rand_int}}
} 

When you're using an environment variable in the body of the request you don't need or shouldn't use the $. The following should work:

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