简体   繁体   English

Gatling:在将 JSON 文件用作请求正文之前更新它的内容

[英]Gatling : Update content of JSON file before using it as request body

{
  "aggregateResults": true,
  "targetTimeSeries": "finalForecast",
  "filter": {
    "id": "f3456789sdsd779sds4488"
  }
}

This the content of my JSON file, I want to change the value of id before sending this JSON as body in a POST request for my gatling script.这是我的 JSON 文件的内容,我想在我的 gatling 脚本的 POST 请求中将此 JSON 作为正文发送之前更改 id 的值。

Since this is small JSON, currently I am passing it to StringBody and replacing the dynamic part to achieve this successfully but this method will not be useful for long JSON responses with which I have to deal with in future.由于这是小 JSON,目前我将它传递给 StringBody 并替换动态部分以成功实现此目的,但此方法对于我将来必须处理的长 JSON 响应将无用。

Please guide.请指导。

You can embed gatling expressions in your JSON.您可以在 JSON 中嵌入 gatling 表达式。

Assuming your desired id is in a session variable called "id" you could have your file like this:假设您想要的 id 在一个名为“id”的会话变量中,您可以拥有这样的文件:

{
  "aggregateResults": true,
  "targetTimeSeries": "finalForecast",
  "filter": {
    "id": "${id}"
  }
}

And then use an ELFileBody instead of a RawFileBody to supply the file.然后使用 ELFileBody 而不是 RawFileBody 来提供文件。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM