Dynamic entry while posting a json body in jmeter - jmeter

I been trying to write jmeter load test for a SAML secured web-service. So for i have a http request sampler which gets the access code and stores in a variable named access_code. But the web-service accepts post request in the form:
api.service.edu/api/authentication with body data as { "code":"${access_code}","redirect_uri":"some site"} .
but whenever I tried running the jmeter , my sampler gives the following error :
Thread Name: Basic App Usage Flow 1-1
Sample Start: 2018-11-07 21:08:50 EST
Load time: 1209
Connect Time: 0
Latency: 1208
Size in bytes: 370
Sent bytes:0
Headers size in bytes: 324
Body size in bytes: 46
Sample Count: 1
Error Count: 1
Data type ("text"|"bin"|""): text
Response code: 500
Response message: Internal Server Error
HTTPSampleResult fields:
ContentType: application/json; charset=utf-8
DataEncoding: utf-8
is it because of the way I am parsing the access_code? if so how can I parse a dynamic value via a json post request?.

HTTP Status Code 500 stands for Internal Server Error, according to HTTP protocol specification the problem is on the server side as client status codes (i.e. malformed requests) should have HTTP Status code between 400 and 499. So I would recommend checking server-side logs, most probably you will be able to figure out what's wrong from them.
It might be the case your ${access_code} variable is not defined, i.e. the relevant Post-Processor failed to extract it from the previous response. Double check it's value using Debug Sampler and View Results Tree listener combination
It might be the case your ${access_code} variable contains some special characters which are not allowed in JSON and must be escaped
Backspace is replaced with \b
Form feed is replaced with \f
Newline is replaced with \n
Carriage return is replaced with \r
Tab is replaced with \t
Double quote is replaced with \"
Backslash is replaced with \\
If your ${access_code} variable contains any of the above - the resulting JSON will be incorrect. To be on the safe side I would recommend replacing your ${access_code} variable reference with __groovy() function call
${__groovy(org.apache.commons.lang3.StringEscapeUtils.escapeJson(vars.get('access_code')),)}
It might be the case you're not sending a proper Content-Type header so make sure to add HTTP Header Manager and configure it to send application/json as the Content-Type

Related

post data with value showing valid response data but same value from regular expression is not showing valid response data in jmeter

When manually entering value in below parameters, it's working fine and showing a valid response.
Below post shows data when values are manually entered:
POST https://qatbagp523.unix.gsm1900.org/wcs/resources/store/11151/quoteHandler/syncQuote
POST data:
{
"opportunityId":"92456",
"quoteNumber":"54044"
}
[no cookies]
But same value captured from regular expression will not show valid response data
Below post data values captured from regular expression
POST https://qatbagp523.unix.gsm1900.org/wcs/resources/store/11151/quoteHandler/syncQuote
POST data:
{
"opportunityId":"92456",
"quoteNumber":"54044"
}
[no cookies]
Even same post data values but manually entered post data is showing valid response but regular expression captured post data is not showing valid response
I observed headers and other valuesm there is no change, could any please resolve how to get response and what could be the cause for this type of issues
Given you send the same requests you should be getting the same responses, if you have different responses - most probably you're sending different requests
Compare 2 requests using View Results Tree listener, they should be exactly the same in terms of request body, request headers, etc.
Check the variable which is stored by the Regular Expression Extractor using Debug Sampler, it might the case there are extra spaces, line breaks, etc.
Use a third-party external sniffer tool like Wireshark or Fiddler as View Results Tree listener doesn't always tell the full story
If you won't be able to figure out the root cause of the issue - consider saving all the request and response data for both Samplers and update your question with the XML file containing these details.

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

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.

jmeter, response header correlation,java

I have a issue in passing dynamic value in request header of jmeter script. Here is the sequence:
Http Request1: Regular expression extractor for extracting the dynamic value from Response Header -- this is ok , variable C_Xscrftokenid2 stores the dynamic string.
Http request2: Pass this C_Xscrftokenid2 Dynamic value to the request Header (web_add_header..)--> Failing
Reason:${C_Xscrftokenid2}-> in the output i dont see the value inside the braces getting replaced with the dynamic value instead i simply see the output as below:
Request Headers:
MaxDataServiceVersion: 2.0
X-Requested-With: XMLHttpRequest
x-csrf-token: ${C_Xscrftokenid2}
May i know the reason?
Thank you.
Make sure in your Regular expression extractor field to check is set to Response Headers as shown below
In your HTTP request 2 Header Manager use ${Variable_Name} to pass extracted variable.
I would suggest you to add a debug sampler and see if it is extracting the variable correctly or not.
If you are getting an empty value in debug sampler result then the problem could be with regular expression you are trying to extract.
In my case i wanted to extract X-Frame-Options from response headers and pass it to next header its working as expected
Follow this link for more information on extracting variables
Check your "HTTP Header Manager" is under the "HTTP sampler" and not at the same level.
Hope this help.

Jmeter - Want redirected URL to be displayed in response data as its giving response code 302 in response header

I have generated a jmeter script.
But I'm not getting anything in response data (View tree listner).
I'm getting Response code: 302 and Response message: Moved Temporarily in response header (View tree listner) also giving the URL to which it is redirected in Location field in response header.
I want this redirected URL to be displayed in response tab.
the url i wnat in response data]1
You can fetch the URL using Regular Expression Extractor.
Add Regular Expression Extractor as a child of the HTTP Request sampler
Configure it as follows:
Field to check: Response Headers
Reference Name: JMeter Variable name of your choice, i.e. location
Regular Expression: Location: (.*)
Template: $1$
You will be able to access the extracted URL as ${location} or `${__V(location)}} where required.
See Using RegEx (Regular Expression Extractor) With JMeter article for more information on correlating dynamic values in JMeter test.

How can i pass dynamic value through Referer URL for HTTP Header Manager in jmeter3.0?

My referer url for My listener request: http://..*.***:****/ecloudbaseweb//app/managecourse?courseid=815
Referer url in Http Header Manager
In the above url, the course id dynamic value.
My scenario:
Step1: I have updated course id for dynamic parameter and updated details for regular expression extractor for manage course http request
Attachment for your reference:
In this configuration, How can i set dynamic values through Referer URL for HTTP Header Manager in jmeter3.0.?
Kindly give me a solution for this scenario
Thanks,
Vairamuthu.
Dear sir,
I have updated, your comments and after changes the below issue occurred..please verify the attachment..
You can use values captured using Regular Expression Extractor in Header manager also, the same way you use in samplers.
Refer the screen shot:
Note: I observed that courseId (AA) is captured in 78 manageCourse request and used in the same request. This might cause in failure as you have not captured the value yet, you can't use it. You need to keep the Regular Expression Extractor in earlier requests than 78, might be under 77 newCoursecreate.
In Jmeter, First sampler is processed, and then the post processor. So, keep the Regular Expression Extractor (post processor) in the sampler (HTTP request), in which response the value (courseID) you want to retrieve is present.

Resources