在jmeter GUI中仅对空格进行编码 [英] Encode only spaces in jmeter GUI
问题描述
我读取了一个csv文件,以输入到我的jmeter测试计划中.我在行query
中命名第一个变量.
I read a csv file for input in my jmeter test plan. I name the first variable in the row query
.
我需要它将空格编码为%20
而不是+
.与${__urlencode(${query})}
一样使用__urlencode()
函数将空格编码为+
,与在上面的屏幕快照中选择参数上的encoding选项的方式相同.
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.
推荐答案
我不认为这是您真正想要的,因为对URL进行编码不仅与空格有关.
I don't think this is something you're really want as encoding the URL is not only about spaces.
您应使用 encodeURIComponent()函数(或其等效项).通过 __javaScript 函数在JMeter中调用它的方式如下:>
You should use encodeURIComponent() function (or its equivalent). The way of calling it in JMeter via __javaScript function will look like:
${__javaScript(encodeURIComponent("${query}"),)}
如果您只需要用%20
替换空格,则可以使用 __groovy来完成()函数,例如:
If you just need to replace spaces with %20
you can do it with __groovy() funciton like:
${__groovy(vars.get('query').replaceAll(' '\, '%20'),)}
演示:
有关更多信息,请参见 Apache JMeter函数-简介文章,以获取更多信息.关于JMeter函数的概念.
See Apache JMeter Functions - An Introduction article for more information on JMeter Functions concept.
这篇关于在jmeter GUI中仅对空格进行编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!