我在jmeter脚本中使用了字符串替换功能,并且在本地计算机上运行该脚本时工作正常,但是在服务器上运行相同的脚本时,它显示错误。
使用的函数是:${__strReplace(${C_Create_Escape},",\\\",)}
其中create escape
是正则表达式。
在服务器上显示400错误,未通过字符串替换功能。
错误:
"timestamp":1547805846520,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"Could not read document: Unexpected character ('\\' (code 92)): was expecting double-quote to start field name\n
at [Source: java.io.PushbackInputStream@463eb3f3; line: 1, column: 2804] (through reference chain:
com.acn.hps.gpp.gibs.dto.FormRequestDTO[\"gibsFormDTO\"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Unexpected character ('\\' (code 92)): was expecting double-quote to start field name\n at [Source: java.io.PushbackInputStream@463eb3f3; line: 1, column: 2804] (through reference chain: com.acn.hps.gpp.gibs.dto.FormRequestDTO[\"gibsFormDTO\"])","path":"/form/createOrEditForm"}
答案 0 :(得分:0)
如果函数参数包含逗号,请确保使用“ \”将其转义,否则JMeter会将其视为参数定界符。
此限制有一个副作用:如果您需要传递反斜杠-您需要使用另一个反斜杠对其进行转义
因此,基本上,如果将"a"
传递给函数,您将得到\"a\"
作为结果:
您的服务器希望使用双斜杠将其转义,例如\\"a\\"
我的假设是,您将需要添加更多的反斜杠,以便同时符合JMeter Functions语法和服务器的期望。结果语法为:
${__strReplace(${C_Create_Escape},",\\\\\\\",)}
查看Apache JMeter Functions - An Introduction文章以获取有关JMeter Functions概念的更多信息。