How to get URL having ".../?where={'key1' : 'value1' , 'key2' : 'value2':.........}" in Jmeter http request - jmeter

I need to load test one Python api in below URL format:
//IP:PORT/Sub_Part/?where={"KEY1":"VALUE1","KEY2":"VALUE2","KEY3":"VALUE3"}
I tried to pass the key value pair through csv as well as directly in http request but getting error message.
java.net.URISyntaxException: Illegal character in query at index 47:
http://IP:PORT/Sub_Part/?where={"KEY1":"VALUE1","KEY2":"VALUE2","KEY3":"VALUE3"}
Here key and value are dummy data I have placed here for easy understanding.
Please help me with correct syntax for this URL.
Thanks in advance for all your help.

In REST APIs, JSON objects are typically sent (POST) or returned in the body of the request. They are not typically encoded as part of the URL.
For a GET request, you can either pass the information as segments in the url or as querystring parameters.
For more details refer here, How to send a GET request with a "/" in the query

As per HTML URL Encoding Reference:
URLs can only be sent over the Internet using the ASCII character-set.
so you need to define the request in JMeter's HTTP Request sampler as follows:
Pay attention to URL Encode? checkbox, it has to be ticked otherwise the parameter will be sent "as is"
Another option is using __urlencode() function like:
http://IP:PORT/Sub_Part/?where=${__urlencode({"KEY1":"VALUE1"\,"KEY2":"VALUE2"\,"KEY3":"VALUE3"})}
which will generate an encoded sequence which you could use in the URL path:
%7B%22KEY1%22%3A%22VALUE1%22%2C%22KEY2%22%3A%22VALUE2%22%2C%22KEY3%22%3A%22VALUE3%22%7D
as you can see, all non-ASCII characters where removed.
Check out Apache JMeter Functions - An Introduction to learn more about JMeter Functions concept.

Related

Passing a mobile number from a CSV with spaces as a param to Jmeter HTTP GET request

New to Jmeter, I want to pass a variable of say "1234 567 8910" from a CSV file as a Param value to a HTTP GET request and I just can't seem to get it to work, tried a number of ways, any ideas ?
Complains with "java.net.URISyntaxException: Illegal character in query at index 71" which is the first space in the param.
Fixed by changing the csv file.....
If you need to pass this phone number as a GET request parameter just tick URL Encode? box in the HTTP Request sampler:
If you need to pass this phone number as a part of a GET request URL path - you can use __urlencode() function to wrap your variable from the CSV file:
${__urlencode(${variableFromCSV})}
Check out Apache JMeter Functions - An Introduction article to get familiarized with JMeter Functions concept.

Jmeter is converting '#' in the Password into junk character

I am recording Login in Jmeter. Password has '#'. Jmeter recorded exact string but when i run the same, '#' is converted to '%40ss' and login is getting failed(login is failing even if i pass parameters through csv file). But if we pass parameters through jmeter Body Data, Login is successful. I dont want to pass through Body Data, i want to send parameters through CSV file. How to achieve this. Please find the attachments
Recorded and Response
My expectation is that it is only a matter of representation, i.e. when I run similar request using a sniffer tool like Wireshark I can see # sign as a part of form data.
Most probably your problem lies somewhere else, i.e. you haven't correlated this __RequestVerificationToken or haven't added HTTP Cookie Manager.
When it comes to load testing ASP.NET web applications you cannot just record and replay your test, you need to perform correlation of dynamic parameters, check out ASP.NET Login Testing with JMeter article for more details.
Lakshmikanth, when you are passing any special character in parameters values then JMeter converts that character into percent-encoding for eg. '#' converts to '%40', '!' converts to '%21'.
To overcome this issue you can pass your password as it is [say P#ssword] in the .csv file but in your request you need to uncheck the encode checkbox corresponding to your password parameter.

In jmeter : how to extract values from two different json response and use that extracted values as a parameter for new http request

In jmeter: I’m using two http requests in one thread group, so I’m getting two response from those http requests.
I need ‘member id’ from one response and some string(digest) from other response, in order to create third http request.
I have extracted 'member id' by using this regular expression: {"Id":(.+?)}
which return me correct member id.
Response from 2nd request is string(digest) : "G9V6Su9PESaobcInErdD7Y8OKNo="
I added one more regular expression to extract this string : "(.+?)"
I have added two debug sampler as I'm using two regular expression extractor.
then I pass extracted values 'member id' and string(digest) as a parameter to third http request.
When I run it I'm getting error, my 3rd http request failed.
It's failing to pass extracted 'member ID', but its correctly pass string(digest)
In first debug sampler: its showing correct extracted 'Member ID' but some different values for digest field.
In 2nd debug sampler: its showing correct extracted 'digest' field but some different value for 'Member ID'.
I’m doing it all under one thread group
I'm new to jmeter, I don’t know whether it is possible to extract field from two different response and use as parameter to create new http request.
if it possible how to do it please help me.
Thanks in advance.
I believe that it's due to including quotation marks (and who knows what else) into the "Id" regular expression, you need to surround it with quotes like:
{"Id":"(.+?)"}
Also the better way of working with JSON data is JSON Path Extractor which is available via JMeter Plugins project. See Using the XPath Extractor in JMeter guide (scroll down to "Parsing JSON") for more information on installation, usage, syntax, etc.

JSON Path Extractor in JMeter

I am new to jmeter. Can anyone help me to use a response object of one request to be passed as a request header of next HTTP request ?
Let me explain.
I am getting an access token along with the response of login in my app:
{: "responseCode":18, : "message":"Successfully logged in.", : "responseObject":"8zWExE4eSdhcJDwnW9MgIw=="}
No I want to use this access token (8zWExE4eSdhcJDwnW9MgIw) as one of the parameter of next request.
I used JSON Path Extractor for this.But its not working.
I am using JSON Path Extractor as well and it works great if it is properly configured.
Just put it into request and fill fields:
Variable Name: access_token (or any other you want to use later in request like this ${access_token})
JSON Path: responseObject should be enough if the JSON you pasted is full response (thjose additional colons are just some mistakes when copy-pasting or the JSON is corrupted?)
Default Value: I always use some value like 'NotUpdated!' here so I can assert in the next step or at least see it easily in request.
Not seeing the full response it is quote hard to come up with a correct JSON Path expression.
Given what you posted it should be something like $.responseObject
See JSON Path Syntax guide for queries syntax examples and Using the XPath Extractor in JMeter (scroll down to "Parsing JSON") for plugin installation instructions and XPath to JSON syntax mapping.
Just in case anybody would face an issue with multiple variable extractions using JSON Extractor (like me), make sure to:
List the names of variables/path expressions/default values using a semicolon as a separator.
Provide default values for every variable.
The second point is apparently required, and I only found out about it from this
Medium post.

Capture a header value from the response in Jmeter and re-use

I'm calling a REST request for authentication. And I need to get the session ID sending on response; in order to reuse that in my next request.
session id comes in Response header. When I use view result tree, this is not showing header parameters(response body has no data).
When googling I found a method using Regular expression Extractor method, but seems it works only when data in response body.
Nope, Regular expression extractor can search in headers also. You need to specify where to search.
See example,
This will search in headers and you can specify in main samples, sub samples also.

Resources