无法从负载中的变量/JSON 文件传递​​值

发布于 2025-01-10 04:21:34 字数 1459 浏览 0 评论 0原文

我试图在有效负载下方传递一个值,我可以从打印中获取它的值,但在有效负载内部无法访问相同的值,它会打印 #(config.Secondary_ED) 作为输出。 config.Secondary_ED 包含一个 IP 地址。当我手动提供 IP 地址时,它工作正常。

    And print config.Secondary_ED
    And request {"agent-forwarding":true,"configuration-data":"{\"service-host\":\"#(config.Secondary_ED)\",\"service-port\":\"8443\",\"user\":\"restdispatcher\",\"protocol\":\"vosrestdispatcher:rest\"}","configuration-template":null,"description":"Change Guardian Default Event Destination sk-12sp5","display-name":"sk-12sp5","ev-prototype-id":"1","forwarding-queries":[""],"id":1,"is-default":true,"is-indelible":true,"method":"vosrestdispatcher:rest","model":"REST Dispatcher","server-fordwarding":false}     
    When method PUT

工作负载

    #And print config.Secondary_ED
    And request {"agent-forwarding":true,"configuration-data":"{\"service-host\":\"1.1.1.1\",\"service-port\":\"8443\",\"user\":\"restdispatcher\",\"protocol\":\"vosrestdispatcher:rest\"}","configuration-template":null,"description":"Change Guardian Default Event Destination sk-12sp5","display-name":"sk-12sp5","ev-prototype-id":"1","forwarding-queries":[""],"id":1,"is-default":true,"is-indelible":true,"method":"vosrestdispatcher:rest","model":"REST Dispatcher","server-fordwarding":false}      

**Secondary_ED 存储在名为 config.js 的 json 文件中

我已经多次使用 # 来获取值,但在这种情况下同样不起作用。 请建议我在这里错过了什么。

感谢您的帮助。

I am trying to pass a value inside below payload, I am able to get the value of it from the print but same is not accessible inside the payload, It prints the #(config.Secondary_ED) as the output.
The config.Secondary_ED contains an ip address. It works fine when I give ip address manually.

    And print config.Secondary_ED
    And request {"agent-forwarding":true,"configuration-data":"{\"service-host\":\"#(config.Secondary_ED)\",\"service-port\":\"8443\",\"user\":\"restdispatcher\",\"protocol\":\"vosrestdispatcher:rest\"}","configuration-template":null,"description":"Change Guardian Default Event Destination sk-12sp5","display-name":"sk-12sp5","ev-prototype-id":"1","forwarding-queries":[""],"id":1,"is-default":true,"is-indelible":true,"method":"vosrestdispatcher:rest","model":"REST Dispatcher","server-fordwarding":false}     
    When method PUT

Working Payload

    #And print config.Secondary_ED
    And request {"agent-forwarding":true,"configuration-data":"{\"service-host\":\"1.1.1.1\",\"service-port\":\"8443\",\"user\":\"restdispatcher\",\"protocol\":\"vosrestdispatcher:rest\"}","configuration-template":null,"description":"Change Guardian Default Event Destination sk-12sp5","display-name":"sk-12sp5","ev-prototype-id":"1","forwarding-queries":[""],"id":1,"is-default":true,"is-indelible":true,"method":"vosrestdispatcher:rest","model":"REST Dispatcher","server-fordwarding":false}      

**Secondary_ED is stored in a json file called config.js

I have used # many times to get the value but same doesn't work in this case.
Please suggest what did I miss here.

Appreciate your help.

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

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

发布评论

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

评论(1

失而复得 2025-01-17 04:21:34

请注意,configuration-data 的值是一个字符串,而不是 JSON 对象。如果不清楚请教懂JS的朋友。

你可以尝试这个(注意 string 的用法):

* string configData = { 'service-host': '#(config.Secondary_ED)' }
* request { foo: '#configData' }

或者只使用 JS 字符串连接(这只是一个猜测,请弄清楚什么对你有用,但你明白了。

* def configData = '"{\\"service-host\\":\\"' + config.Secondary_ED + '\\"'

Please notice that the value of configuration-data is a string, not JSON object. Ask a friend who knows JS if this is not clear.

You can try this (note the usage of string):

* string configData = { 'service-host': '#(config.Secondary_ED)' }
* request { foo: '#configData' }

Or just use JS string concatenation (this is just a guess, please figure out what works for you, but you get the idea.

* def configData = '"{\\"service-host\\":\\"' + config.Secondary_ED + '\\"'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文