0

我正在尝试捕获从 HTTP 请求创建的有效负载(以 JSON 格式)并将其作为值传递给下一个 API 请求。

Step1:创建 Http 请求负载。下面的示例:

{  
   "fdCustomerId":"${cuid}",
   "account":{  
      "type":"CREDIT",
      "credit":{  
         "cardNumber":"ENC_[${Output2}]",
         "nameOnCard":"John Smith",
         "cardType":"${cardtype}",
         "cardSubType": "${cardsubtype}",
         "billingAddress":{  
            "type":"work",
            "country":"US",
            "primary":true
         }
}

Step2:使用后期处理将最终的 Payload 捕获到变量中

var requestBody = ctx.getCurrentSampler().getArguments().getArgument(0).getValue();
vars.put("requestBody", requestBody);
log.info("###########################################Request     Body are:##########" + requestBody);

Step3:将RequestBody变量作为值传递给下一个HTTP请求

{ 
 "category": "GBS_ExecMetrics_UCom", 
 "consumed": false, 
 "data": { "Test Case Id": "AB_CMS_006_CC_001_500_", 
         "Account Number": "0001210520779700304", 
         "Primary Card Number": "**${requestBody}**",  
         "Secondary Card Number": "0000377883144114646",  
         "Run Date Time": "03/26/201917:30"}

}

当我到达端点时,我收到以下错误消息:

{“错误”:“BadRequest:请提供有效的 Json”...

如何将其转换为字符串或在函数中包含转义字符并传递请求正文?

4

1 回答 1

0

我对步骤 1 中采用的示例请求语法不好。以上步骤按原样工作。

更正了如下语法并能够传递 json。谢谢。

{  
"fdCustomerId":"${cuid}",

"account":{
"type":"CREDIT", "credit":{
"cardNumber":"ENC_[${Output2}]", "nameOnCard":"John Smith", "cardType":"${cardtype} ", "cardSubType": "${cardsubtype}", "billingAddress":{
"type":"work", "country":"US", "primary":true } } } }

于 2019-05-01T13:39:38.693 回答