JMETER - HTTP Request - Client secret

39 views
Skip to first unread message

Quynh Ly

unread,
Jan 18, 2022, 11:12:05 AM1/18/22
to BlazeMeter Forum
  Hello All SMEs,

I need your help....

I am trying to generate a token for my application using grant type, client id and client secret .  However, client secret value has a symbol '~' in it.  Thus, it causes error.  How do I handle '~' sign in the client secret properly?  Please kindly advise.  I appreciate in advance for your great help!!! 

Javier Cortavitarte

unread,
Jan 18, 2022, 1:26:42 PM1/18/22
to BlazeMeter Forum

Hello!

When generating a token via Grant type for these objects: client_id & client_secret. this is possible due to the encoding type since generally the default option is base64 which supports alphanumeric digits (see answers in this forum thread)

Thus it's likely that you'll need to define the relevant schema supporting such encoding with special characters, or using the default option as explained in the forum thread shared. And, here's another point of reference for this situation which can work as a workaround. 

Hope this help you. 
J

Dmitri T

unread,
Jan 18, 2022, 11:55:36 PM1/18/22
to BlazeMeter Forum
Depending on how you're passing the client secret you can either tick "URL Encode?" box in the HTTP Request sampler
Untitled1.png

or use __urlEncode() function where required (see Apache JMeter Functions - An Introduction article to learn more about JMeter Functions concept)

Untitled.png

Quynh Ly

unread,
Jan 20, 2022, 7:34:55 PM1/20/22
to BlazeMeter Forum

Hello Javier,

It said ---> Use secret after encoding and it works.  Can you advise how and where should i enter the following code :( ???



import java.net.URLEncoder; String url = "osi5oX-:?0A3YiG4aCpZ.Y[+PW51pZVY" String encodedUrl = URLEncoder.encode(url, "UTF-8" ); println(encodedUrl)​

Dmitri T

unread,
Jan 21, 2022, 1:29:12 AM1/21/22
to BlazeMeter Forum
You can go for JMeter Functions, for example __urlencode() should do the trick for you:

${__urlencode(osi5oX-:?0A3YiG4aCpZ.Y[+PW51pZVY)}

if you prefer to use the code you're shared you can go for __groovy() function like:

${__groovy(URLEncoder.encode("osi5oX-:?0A3YiG4aCpZ.Y[+PW51pZVY"\, "UTF-8" ),)}

however it uses more or less the same code under the hood hence will produce the same output:

Untitled.png

Quynh Ly

unread,
Feb 19, 2022, 12:04:24 AM2/19/22
to BlazeMeter Forum
Can you please show how do I implement  ${__urlencode(osi5oX-:?0A3YiG4aCpZ.Y[+PW51pZVY)}.  I still do not understand by the looking at the screen above.  I am new to  Jemter and your help is greatly appreciated.

Quynh Ly

unread,
Feb 19, 2022, 10:02:10 PM2/19/22
to BlazeMeter Forum
Hello, 

My client secret contains a tilda sign ~.
My goal is to use urlencode function for the client secret.  Then, the econded client secret will be used in JSON Extractor and Beanshell Assertion.  I tried this but still get the invalid client secret.  Can you please advise.
Capture.PNG

Dmitri T

unread,
Feb 21, 2022, 12:49:13 AM2/21/22
to BlazeMeter Forum
We cannot "advice" you anything because we don't know how exactly this "tilda" needs to be encoded, i.e. which encoding needs to be used

For example JavaScript encodeURIComponent leaves the "tilda" intact and percent encoding translates it to %7E

Reply all
Reply to author
Forward
0 new messages