Encode only spaces in jmeter GUI

2019-08-19 10:05发布

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

Http request

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.

标签: http jmeter
1条回答
女痞
2楼-- · 2019-08-19 10:33

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:

JMeter Functions

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

查看更多
登录 后发表回答