如何在请求主体中使用{{$ randomint}}并将其保存在环境中
我正在尝试使用{{$ 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您在请求正文中使用环境变量时,您不需要或不应该使用
$
。以下应该有效: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: