简体   繁体   中英

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

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. I do not want JMeter to repalces spaces with %20, how can I do that

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

You can't send space in URL :

A URL must not contain a literal space. 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).

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 . So do 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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