简体   繁体   English

Groovy JMeter传递带空格的字符串,避免%20

[英]Groovy JMeter Passing a string with spaces, avoiding %20

I have an API which it's URL requires a string with spaces --> ABCI have tried 我有一个API,它的URL需要带空格的字符串-> ABCI尝试过

String X = "A B C";
vars.put("myKey",X);

GET  https://myserver.com/Api/v1.0/config/${myKey}   

When JMeter executes this it replaces spaces with %20 in url. 当JMeter执行此操作时,它将在URL中用%20替换空格。 I do not want JMeter to repalces spaces with %20, how can I do that 我不希望JMeter用%20替换空格,我该怎么做

GET https://myserver.com/Api/v1.0/config/A%20B%20C

You can't send space in URL : 您不能在URL中发送空格

A URL must not contain a literal space. URL不能包含文字空间。 It must either be encoded using the percent-encoding or a different encoding that uses URL-safe characters (like application/x-www-form-urlencoded that uses + instead of %20 for spaces). 必须使用百分比编码或使用URL安全字符的其他编码对它进行编码(例如application / x-www-form-urlencoded使用+而不是%20来表示空格)。

But you can use + instead of space 但是您可以使用+代替空格

And notice that server/receiving end will decode it back to spaces so there isn't a real issue. 并且请注意,服务器/接收端会将其解码回空格,因此这不是真正的问题。

Usually browser replaces spaces entered into the address bar with %20 . 通常,浏览器用%20替换在地址栏中输入的空格。 So do JMeter. JMeter也是如此。

You have to update your API, so URL param with %20 should be interpreted as a string with a space(s) by your API. 您必须更新您的API,因此API会将具有%20 URL参数解释为带空格的字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM