[英]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.