Reputation: 21
JMeter script recording capture JSON post request with three escape character(\) and rerun as it is without parameterization it works fine. But if we use any Variable "${xyz}" anywhere in the request body and run in JMeter, all the three slashes(\) becomes two slashes(\) while passing the request to application. Then the request failed as "BAD Request" as application doesn't accept request with two slashes.
I have already tried "FileToString" method but no success.
"Draft":{
"id": 123654656,
"draftdata":{\\\"accCat\\\":\\\"207\\\",\\\"accNumber\\\":\\\"656565
\\\",\\\"id\\\":${Var_ID},...}
}
"Draft":{
"id": 123654656,
"draftdata":{\\\"accCat\\\":\\\"207\\\",\\\"accNumber\\\":\\\"656565
\\\",\\\"id\\\":9876,...}
}
When i pass request with variable the request becomes like below and can be seen in results tree as request body
"Draft":{
"id": 123654656,
"draftdata":{\\"accCat\\":\\"207\\",\\"accNumber\\":\\"656565
\\",\\"id\\":${Var_ID},...}
But without parameterization variable it works perfectly as request goes with three slashes(\).
Upvotes: 2
Views: 1866
Reputation: 1
Had same issue. I have URL encoded request body by using online tool and unchecked the URL Encode check box of parameters in JMeter then replaced correlation and parameterized values with variables. Its worked without any errors.
Upvotes: 0
Reputation: 1
https://bz.apache.org/bugzilla/show_bug.cgi?id=63255 I added simple JMX test, showing the inconsistent behavior there. Jmeter 5.3 still has it.
Upvotes: 0
Reputation: 31
I'm having the same issue in JMeter 5.1. I have JSON that that is embedded in JSON. Example:
{"messages":"{\"outputs\":[\"{\\\"objectstatus\\\":\\\"${__Random(100,200,)}\\\"}\"]}"}
What would be posted is this, which is invalid JSON:
{"messages":"{\"outputs\":[\"{\\"objectstatus\\":\\"152\\"}\"]}
Even if I move all of the functions out of the request body and only use variable substitution, the same thing happens.
The workaround is to "double escape" everything. Meaning \" becomes \\"
and \\\" becomes \\\\\\".
Upvotes: 1
Reputation: 168157
I cannot reproduce your issue using the payload in a plain text file and __FileToString() function
JMeter sends the text data exactly as it is including triple back slashes in appropriate places. I even captured the request using Wireshark sniffer tool to exclude potential issue with the View Results Tree listener
It might be the case you're suffering from a form of issue which has already been fixed in the latest JMeter release, according to JMeter Best Practices you should always be using the latest version of JMeter so make sure to upgrade to JMeter 5.1 or whatever is the latest available version from JMeter Downloads page and you should be able to use parameterisation without any problems.
Upvotes: 0