当使用jmeter变量在Jmeter中的GraphQL HTTP请求“Variable”中传递值时,会添加额外的双引号

fhg3lkii  于 2023-10-20  发布在  其他
关注(0)|答案(1)|浏览(161)

我想在Jmeter中使用GraphQL HTTP请求发送以下请求-

{"pageName":"TEST_SCREEN","section":"TEST_SCREEN","action":{"name":"includeObjects","fields":[{"fieldName":"id_","value":"101"},{"fieldName":"id_","value":"102"},{"fieldName":"id_","value":"103"}]}}

我动态地生成“fields”的值,它可以有任意数量的条目。所以我为字段生成了值,并预先存储在一个变量中,如下所示:

String request = "[";
for (int i = 0 ;i<items.length;i++) {
    if (!"[".equals(request)) {
        request +=",";
    }   
    request += "{\"fieldName\":\"id_\",\"value\":\""+items[i]+"\"}";
}
request += "]";
vars.put("ITEMS_ID_REQUEST",request);

然后在graphQL示例中,在变量下我这样给出-

{"pageName":"NEW_PAGE","section":"NEW_FILTER_PAGE","action":{"name":"includeAction","fields":"${ITEMS_ID_REQUEST}"}}

JMeter正在发送以下reuest-

{"pageName":"TEST_SCREEN","section":"TEST_SCREEN","action":{"name":"includeObjects","fields":"[{"fieldName":"id_","value":"54794"},{"fieldName":"id_","value":"54795"},{"fieldName":"id_","value":"54796"},{"fieldName":"id_","value":"54797"},{"fieldName":"id_","value":"54798"}]"}}

我的样本不合格。我注意到应该是[{..}]的字段的值现在被括在双引号中,这会扰乱JSON请求。我知道我们必须把JMeter变量用双引号括起来,所以删除它们不起作用,所以我试图转义双引号,但这也不起作用。如何在没有双引号的情况下正确替换所需的值?提前感谢!

p3rjfoxz

p3rjfoxz1#

好吧,我认为这是谁添加了“双引号”,而不是JMeter

"fields":"${ITEMS_ID_REQUEST}"}}                                         
         ^ here              ^ and here

所以只要删除它们,它们就会在您的“下面请求”中消失。
也许使用JsonBuilder比字符串连接更方便生成JSON?
更多信息请参阅:

相关问题