简体   繁体   English

邮递员:如何在请求正文中使用环境变量

[英]Postman: How to use environment variables in Request Body

I am trying to replace the value of JSON Body in the Postman from environment variable, and the value is actually replaced but it converts the JSON into a string when passed to the POST request so the request eventually fails since the POST request expects JSON body..我正在尝试从环境变量中替换 Postman 中 JSON Body 的值,该值实际上已被替换,但它在传递给 POST 请求时将 JSON 转换为字符串,因此请求最终失败,因为 POST 请求需要 JSON 正文。 .

For example, Here is the below request and the variables are already declared with values in the Postman例如,这是下面的请求,并且变量已经在 Postman 中声明了值

邮递员尸体截图

And once the request is sent, the entire body is converted to String.一旦请求被发送,整个正文被转换为字符串。 Any idea how to keep the body is JSON even after substituting the value for the variable and not let it convert to String?即使在替换变量的值并且不让它转换为字符串之后,知道如何保持主体是 JSON 吗?

在此处输入图片说明

Example, I have environment variable : variable name = port, initial value = 4242, current value = 4242. variable name = name, initial value = abcd, current value = abcd.例如,我有环境变量:变量名 = 端口,初始值 = 4242,当前值 = 4242。变量名 = 名称,初始值 = abcd,当前值 = abcd。 To use environment variable as request body, use this in request body:要将环境变量用作请求正文,请在请求正文中使用它:

{
 "string": "{{name}}",
 "number": {{port}}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在请求正文中使用 {{$randomInt}} 并将其保存在环境中 - How to use {{$randomInt}} in request body and save it in environment 如何在邮递员测试主体的另一个请求测试主体中使用来自一个请求的变量? - How to use variable from one request in another request test body in postman test body? 邮递员:在主体中传递环境变量时,MD5验证失败 - Postman: MD5 validation failed when passing environment variables in body Postman 解析请求正文对变量进行计算并每月返回新数据 - 如何? - Postman Parsing request body make calculations on variables and return new data monthly- how? Postman:在环境变量的声明中使用请求名称 - Postman: Use the request name within the declaration of an environment variable 如何在 postman 的环境中获取多个值并将其保存为不同的变量? - How to fetch and save multiple values as different variables in environment for postman? 如何遍历 postman 中的数组以更改环境变量 - How to iterate through an array in postman to change environment variables 在 Postman 中发送带有正文的请求 - Sending request with text body in Postman 如何在一个地方保存邮递员请求正文并在运行时通过 - How to save a postman request body in one place and pass when run 如何在 postman 测试中检查请求正文是否有密钥 - How can I check request body has a key or not in postman tests
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM