post data with value showing valid response data but same value from regular expression is not showing valid response data in jmeter - 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.

Related

How I extract the x-csrf-token in request header and pass to post https request in jmeter?

I can't extract the x-csrf-token and pass . I got error like csrf token expired [![enter image description here]
Anyone give some exact ans and support.
Your question doesn't contain sufficient level of details so it cannot be answered comprehensively.
First of all check your ${x} JMeter Variable value using Debug Sampler and View Results Tree listener combination
Then check the request header using the aforementioned View Results Tree listener. The token should be exactly the same as the one returned in the previous request.
Also it seems that your token comes in JSON-like structure, JSON is not a regular language so it would be a better idea considering using JSON Extractor instead of Regular Expression Extractor

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.

In JMeter Post Data Not Sent In Request When Certain Character Strings Are Included

In a test plan that I am trying to execute, there is a step that includes a post request with post data. One of the parameters in the post data includes special characters. The parameter name is '__RequestVerificationToken'. When the parameter name is spelled correctly, the request is sent with no post data included. The request fails. However when the parameter is changed slightly, post data will be included with the request. Because the correct parameter names are not sent, the request also fails. Below is a list of parameter names that do and do not break the sending of post data.
Parameter names that do break the sending of post data:
'__RequestVerificationToken'
'__RRequestVerificationToken'
'**RequestVerificationToken'
Parameter names that do not break the sending of post data:
'__TRequestVerificationToken'
'RequestVerificationToken'
Is there anything that I can do have my parameter name sent correctly without dropping post data from the request?
Did you try encoding them using 2 options:
In Http Request check the checkbox encode in the parameters table
Use function __urlencode

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.

Overwriting HTTP response headers

Is there a way to overwrite the http response headers returned in Jmeter? I'm testing a web service that returns JSON and when an invalid request is sent, the JSON response returned doesn't contain application/json (or any for that matter) in the response header. If I save the response to a file, I see the actual JSON returned, but looking at the response in a Results tree doesn't show a response. Unless there is a way to load the response from file and parse the error message from the file, I'm hoping to somehow overwrite the HTTP response header and force jmeter to treat the response as JSON.
Any suggestions are welcome!
Using a beanshell post processor, you can write some script that would force the value for the header, or write out to a file.
You can also add a listener that would write the results to file for you. Granted - this is less convenient for debugging then Tree View.
As it turns out JMeter does not support response header overloading. While the response isn't displayed in the Results tree, it is actually available to other assertions. I was able to still provide assertions to validate responses even though the response was missing from the GUI.

Resources