JMeter CompoundVariable.execute method is replacing + character with empty space - image

I'm trying to substitute a value into a JSON request body using a JMeter variable and ${value_here} notation. The value is a base64 encoded image, which includes "+" characters.
When I call CompoundVariable.execute, the request body contains the value in the JMeter variable, but all "+" characters have been replaced with empty strings resulting in a malformed image.
Is there some workaround for this, or do I need to work around it in code? Simplified example before, since I am sure none of you want the wall of text that would be my encoded image.
String stored in variable (truncated for brevity):
/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCADDASsDASIAAhEBAxEB/8QAHQAAAQQDAQEAAAAAAAAAAAAABQAEBgcBAgMICf/EAEkQAAEDAwMBBAYECwYGAgMBAAECAwQABREGEiExBxNBURQVImFxgTJUkZIIIzM0QnSTobGy4SREYnPB0RZSY4KD8BhyF1NkhP/EABkBAAMBAQEAAAAAAAAAAAAAAAABAgMEBf/EACgRAAICAgICAQMEAwAAAAAAAAABAhESMQMhQVETInGhMkJhsVKR8P/aAAwDAQACEQMRAD8A9U1o44hsZcWlI8ycU1uk1NvgvSXOdieE+Z8B86BItwlOF+8K9KeVyGl/Qb9yU/60CboPi4Q+f7Uz98Vn1hD+tM/fFBRbIRORCYx4juxxSTbYPUwo3zQKdCyDXrCH9aZ++KXp8P60z98UG9WQfqUbn/piserYPP8AYY5A8e7FFBkGvT4f1pn74penw/rTP3xQY22ABlUOMP8AxjmserYOfzKMf+wUUGQa9YQ/rTP3xS9YQ/rTP3xQU26Dn80jEe5sVk22DwBCj8/4BRQZBn1hD+tM/fFL1hD+tM/
Variable in templated request is ${Document_Image_Front} though I'm sure that is irrelevant.

You can use __urlencode function to encode space to + back
${__urldecode(Word "school" is "école" in french)}
returns Word+%22school%22+is+%22%C3%A9cole%22+in+french.

Related

Jmeter Regular expression extractor and parsing into request

In Jmeter, I can able to extract the value using regular expression extractor, but while parsing the value I need some changes in the value as below.
Example,
Suppose If I extract this value in regular expression extractor (single Value in multiple lines),
PHNhbW+xwO
U0FNTDoyL
cmFjbGUu+
Here
I Need to replace + by %2B, need to add %OD%OA at the end of each line and multiple lines to a single line as below.
PHNhbW%2BxwO%OD%OAU0FNTDoyL%OD%OAcmFjbGUu%2B%OD%OA
I need to parse this as a single parameter value.
I think you can use __javaScript() function which allows calling arbitrary JavaScript code and inside JMeter __javaScript() funciton you can call EcmaScript EncodeURIComponent() function
It will automatically convert all newline characters \r\n to %OD%OA and + to %2B and in fact any character except alphanumeric and these ones:
_ . ! ~ * ' ( )
Demo:
See Using JMeter Functions guide for comprehensive information on how to deal with the functions in JMeter

jmeter how to capture an url encoding value and sending it without re-encoding

I'm having problems with a value who is already in url encoding, I capture it fine but when I'm goin to send it, the value is re-encoded...
This is the value:
_TSM_CombinedScripts_=%3b%3bSystem.Web.Extensions%2c+Version%3d4.0.0.0%2c+Culture%3dneutral%2c+PublicKeyToken%3d31bf3856ad364e35%3aes type="text/javascript">
I'm using a RegEx to capture:
Reference name: RSM
Regular Expression: _TSM_CombinedScripts_=(.+?)" type="text/javascript">
And I put a BSF Sampler to see the captured value, and is fine.
But when I put the value in the fields that send it to the server in a post method (rsmScriptManager_TSM=${RSM})the value is re recoded again like this:
rsmScriptManager_TSM=%253b%253bSystem.Web.Extensions%252c%2BVersion%253d4.0.0.0%252c%2BCulture%253dneutral%252c%2BPublicKeyToken%253d31bf3856ad364e35%253aes
Note that, for example at the begining of the chain is:
%253b%253bSystem.Web.Extensions
The literal value is :
;;System.Web.Extensions
The ";;" are url encoding as %3b%3b, and exactly like that I'm capturing it, but when is send it to the server is re encoding the "%" with the %25
(HTML URL Encoding Reference)
And istead of %3b%3b value is sending %253b%253:
%253b%253bSystem.Web.Extensions
And is doing the same for other characters like "+"
How do I fix this?
Make sure that you don't have Encode? box ticked for the extracted request parameter
There is also __urldecode function which can be helpful.
For more information on __urldecode and other useful JMeter functions check out How to Use JMeter Functions posts series

What constitutes a valid URI query parameter key?

I'm looking over Section 3.4 of RFC 3986 trying to understand what constitutes a valid URI query parameter key, but I'm not seeing a clear answer.
The reason I'm asking is because I'm writing a Ruby class that composes a URI with query parameters. When a new parameter is added I want to validate the key. Based on experience, it seems like the key will be invalid if it requires any escaping.
I should also say that I plan to validate the key. I'm not sure how to go about validating this data either, but I do know that in all cases I should escape this value.
Advice is appreciated. Advice in the context of how validation might already be possible through say a Ruby Gem would also be a plus.
I could well be wrong, but that spec seems to say that anything following '?' or '#' is valid as long. I wonder if you should be looking more at the spec for 'application/x-www-form-urlencoded' (ie. the key/value pairs we're all used to)?
http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1
This is the default content type. Forms submitted with this content
type must be encoded as follows:
Control names and values are escaped. Space characters are replaced by +', and then reserved characters are escaped as described in [RFC1738], section 2.2: Non-alphanumeric characters are replaced by %HH', a percent sign and two hexadecimal digits representing the ASCII code of the character. Line breaks are represented as "CR LF" pairs (i.e., `%0D%0A').
The control names/values are listed in the order they appear in the document. The name is separated from the value by =' and name/value pairs are separated from each other by &'.
I don't believe key=value is part of the RFC, it's a convention that has emerged. Wikipedia suggests this is an 'W3C recommendation'.
Seems like some good stuff to be found searching on the application/x-www-form-urlencoded content type.
http://www.w3.org/TR/REC-html40/interact/forms.html#form-data-set

Trouble in passing "=" (equal) symbol in subsequent request - Jmeter

I newly started using jmeter.
my application returns an url with encryption value as response which has to be passed as request to get the next page. The encryption value always ends with "=" ex. "http://mycompany.com/enc=EncRypTedValue=". while passing the value as request, the "=" is replaced with some other character like '%3d' ex "http://mycompany.com/enc=EncRypTedValue%3d" . Since the token has been changed my application is not serving the request.
It took me a while to understand this, unlike other languages and environments in network standards URIs (URLs) do not use quotes or some escape characters to hide special characters.
Instead, a URL needs to be properly encoded by encoding each individual parameter separately in order to build the complete URL. In JavaScript encoding/decoding of the parameters is done with encodeURIComponent() and decodeURIComponent() respectively.
For example, the following:
http://example.com/?p1=hello=hi&p2=three=3
should be encoded using encodeURIComponent() on each parameters to build the following:
http://example.com/?p1=hello%3Dhi&p2=three%3D3
Note that the equal sign used for parameters p1= ... p2= remain as is.
Do not try encode/decode the whole URL, it won't work. :)
Do not be fooled by what is displayed on a browser address bar/field, that is only the human friendly string, the moment you copy it to the clipboard the browser will encoded it.
Hope this helps someone.
Your application has a problem then, because that's the way it should be sent. Url parameters should be encoded as specified in rfc3986. Browsers can do it automatically even, so that's something that should be fixed on your web app, if it is not working.
If data for a URI component would conflict with a reserved character's
purpose as a delimiter, then the conflicting data must be
percent-encoded before the URI is formed.
reserved = gen-delims / sub-delims
gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "#"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
What you are experiencing is URL Encoding - = is a reserved character in URLs and you cannot just append it to your URL unencoded. It needs to be encoded. This obviously already happened in your case. On the server side the url parameters need to be decoded again. This is the job of the container normally, though.
Basing on your use case you may with to consider one of the following approaches:
You can use Regular Expression Extractor Post Processor to capture you response and store it to JMeter variable. As variables as Java Unicode Strings you shouldn't experience any problem with extra encoding of your "=" symbol.
JMeter provides __urldecode function which you can utilize to decode your request.
You can pre-process the request with kind of __Beanshell function or BeanShell preprocessor to decode the whole URL with something like:
URLDecoder.decode(vars.get("your_URL_to be decoded"),"encoding");
If your are adding encryption values in the subsequent request as request parameter then make sure 'Encoding?' is unchecked
Use quotes for your values. E.g. -Jkey="val=ue"

How can i send a parameter with space to .net web api

I would like to receive a long string the contains spaces to my method in my web api
To my understanding i can't send a parameter with white spaces, does it have to be encoded in some way?
EDIT:
My content type is:
Content-Type: application/x-www-form-urlencoded
I've changed it to several other types but none of them allows me to receive a parameter with + instead of spaces
my post method signature is
public HttpResponseMessage EditCommentForExtension(string did, string extention, string comment)
Usually, parameters to an HTTP GET request are URL encoded. This means (among other) that spaces are replaced by "+".
Using + to mean "space" in a URL is an internal convention used by some web sites, but it's not part of the URL encoding standard. If you want to use + to means spaces, you are going to have to convert them yourself.
As you discovered, spaces (like everything else that needs encoding) should be encoded with %XX where X standards for a hex digit.
http://www.w3.org/Addressing/rfc1738.txt
The only thing that work for me is to add %20 instead of the spaces

Resources