You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Wiremock:如何将响应体随机transactionID传入postServeActions

Wiremock中复用响应内生成的随机transactionID到postServeActions

要实现这个需求,你可以利用Wiremock的**场景变量(Scenario Variables)**来存储生成的随机transactionID,然后在响应和postServeActions中复用这个变量。具体配置如下:

{
  "scenarioName": "transaction-flow",
  "response": {
    "status": 200,
    "headers": {"Content-Type": "application/json"},
    "body": {
      "transactionID": "{{setScenarioVariable name='transactionID' value='{{randomValue length=12 type='NUMERIC'}}'}}",
      "statusCode": "S01"
    }
  },
  "postServeActions": [
    {
      "name": "webhook",
      "parameters": {
        "method": "POST",
        "url": "http://127.0.0.1:8081/sts/ADD?FILENAME=transactions.txt&LINE={{scenarioVariable name='transactionID'}}&ADD_MODE=FIRST&UNIQUE=TRUE"
      }
    }
  ]
}

关键配置说明:

  • scenarioName:启用场景变量功能,名字可自定义(只要在当前映射中唯一即可)。
  • setScenarioVariable:生成随机transactionID的同时,将其存入名为transactionID的场景变量中,确保响应和后续动作使用同一个值。
  • scenarioVariable:在postServeActions的URL中引用之前存储的场景变量,替换原有的<transactionID>占位符。

这样配置后,每次请求触发该映射时,生成的随机transactionID会同时出现在响应body和webhook请求的参数中,保证两者一致。

内容的提问来源于stack exchange,提问作者Amit Eshed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 07:42:36