邮递员-嵌套环境变量 [英] Postman - Nested Environment Variables

查看:92
本文介绍了邮递员-嵌套环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在Postman中制作包含其他变量的环境变量的方法。例如:{Server} = localhost; {Port} = 9200; {ServerUrl} = {Server}:{Port}。

I'm looking for a way to make environment variables in Postman, that contain other variables. For example: {Server}=localhost;{Port}=9200;{ServerUrl}={Server}:{Port}.

类似于Make ...

Like in Make...

这种方式似乎不适用于Postman。

This way it doesn't seem to work with Postman.

编辑:

我的尝试:

My attempt:

推荐答案

您可以执行此操作,但我不推荐这样做,似乎您失去了创建一组变量然后通过选择其他环境文件来更改这些变量的值的好处。

You could do it but I wouldn't recommend it, just seem like you're missing the benefit creating a set of variables and then changing the values of these by selecting a different environment file.

添加此字符串 {{ElasticsearchProtocol}}:// {{ElasticsearchServer}}:{{ElasticsearchPort}} 作为环境文件上的 ElasiticsearchUrl 变量。

Add this string {{ElasticsearchProtocol}}://{{ElasticsearchServer}}:{{ElasticsearchPort}} as the ElasiticsearchUrl variable, on the environment file.

或者您可以将其添加到 Pre-Request脚本

Or you could add this to the Pre-Request Script:

let ElasticsearchProtocol   = pm.environment.get('ElasticsearchProtocol')
let ElasticsearchServer     = pm.environment.get('ElasticsearchServer')
let ElasticsearchPort       = pm.environment.get('ElasticsearchPort')

pm.environment.set("ElasticsearchUrl", `${ElasticsearchProtocol}://${ElasticsearchServer}:${ElasticsearchPort}`)

这篇关于邮递员-嵌套环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆