Encode only spaces in jmeter GUI

2019-08-19 10:29发布

问题:

I read a csv file for input in my jmeter test plan. I name the first variable in the row query.

I need it to encode spaces as %20 not +. Using the __urlencode() function like ${__urlencode(${query})} encodes the spaces as + the same way selecting the encode option on the parameter does in the above screenshot.

回答1:

I don't think this is something you're really want as encoding the URL is not only about spaces.

You should use encodeURIComponent() function (or its equivalent). The way of calling it in JMeter via __javaScript function will look like:

${__javaScript(encodeURIComponent("${query}"),)}

If you just need to replace spaces with %20 you can do it with __groovy() funciton like:

${__groovy(vars.get('query').replaceAll(' '\, '%20'),)}

Demo:

See Apache JMeter Functions - An Introduction article for more information on JMeter Functions concept.



标签: http jmeter