I have an HTTP Request sampler in JMeter which sends a login request.
I have to obtain the access_token from the response of this HTTP request which has to be sent along with the request header of the 2nd HTTP request Sampler.
The response data of login request is something like this:
{"status":true,"access_token":"91kLM68tdMBoDFRURArvdmwYgWV9Nr2sHYDwivTM.91kLM68tdMBoDFRURArvdmwYgWV9Nr2sHYDwivTM.Arvdm_M68-BoDFRURArvdmwYgWV9Nr2sHYDwivTM"}
Regular Expression Extractor
Reference Name: access_token
Regular expression: access_token":"(.*?)"
Template $1$
MatchNo:1
When I am checking this regular expression using View Results Tree->RegExp Test, I am obtaining a result like this:
Match count: 1
Match[1][0]=
access_token":"91kLM68tdMBoDFRURArvdmwYgWV9Nr2sHYDwivTM.91kLM68tdMBoDFRURArvdmwYgWV9Nr2sHYDwivTM.Arvdm_M68-BoDFRURArvdmwYgWV9Nr2sHYDwivTM"
Match[1][1]=
91kLM68tdMBoDFRURArvdmwYgWV9Nr2sHYDwivTM.91kLM68tdMBoDFRURArvdmwYgWV9Nr2sHYDwivTM.Arvdm_M68-BoDFRURArvdmwYgWV9Nr2sHYDwivTM
What I need is to obtain Match[1][1]. ie just the access_token value.
Referring the value of the expression in my HTTP Header Manager of the 2nd HTTP request Sampler:
Name: Authorization
Value : Bearer ${access_token}
Now when I am running my JMeter test and observe the View Results Tree, I can see that the response of the second request is
Global Authentication Failed
and the Request Headers:
Connection: keep-alive
problem is in the following line: I have to get the access_token value (91kLM68tdMBoDFRURArvdmwYgWV9Nr2sHYDwivTM.91kLM68tdMBoDFRURArvdmwYgWV9Nr2sHYDwivTM.Arvdm_M68-BoDFRURArvdmwYgWV9Nr2sHYDwivTM) instead of ${access_token}:
Authorization: Bearer ${access_token}
Content-Type: application/json
Content-Length: 21
Host: localhost
User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_111)
If instead of giving the reference token I am hard-coding the token in HTTP Header Manager then the response is successful.
Note: I have already checked [How to get Response Data and parse it to HTTP Header Manager in JMeter
How can I solve this issue?
Most likely your Regular Expression Extractor fails due to extra space or line break or whatever.
Be aware that since Apache JMeter 3.0 you have JSON Extractor which is designed for getting data from JSON response types using Json Path language. The relevant JSON Extractor configuration would be as simple as:
See API Testing With JMeter and the JSON Extractor article for more information on.
Apart from this, the remaining elements configuration in your Test Plan looks fine.
Related
We are using JMeter for salesforce application performance testing and the request information is sent using parameters and one of the parameters holds the Json message and when we execute the request we are getting as
/{"event":{"descriptor":"markup://aura:systemError","attributes":{"values":{"message":"[AuraClientInputException from server] Unexpected request input. Expected input format: "Data in a request must be a valid JSON Object and must be in the expected format."."}}
when i have validated the request using Json format validator it is valid json however when take the request sent from the view result tree it is not a valid json, something went wrong or JMeter has modified the message. anybody has faced this issue any solution is appreciated.
It's hard to say anything without seeing your HTTP Request sampler configuration
Normally if you add your JSON to the "Body Data" tab of the HTTP Request sampler:
and add a HTTP Header Manager configured to send Content-Type header with the value of application/json
the request should reach the server "as it is"
If you have doubts whether your JMeter setup is correct you can just record the relevant request using JMeter's HTTP(S) Test Script Recorder
We have a recorded script using Blaze Meter(HTTPS call) and run in JMeter, One POST request getting failed and shows "500 Internal Server error". In Post request, JSON passed in form of "form-Data" as parameter. When endpoint executed we observed Webkitformbounday in HTTP header, Please give some solution for
HTTPs Request
HTTP Header Manager
POST Request Body
enter image description here
It looks like the recording solution you're using isn't very suitable for building proper HTTP POST request, I would suggest the following amendments:
Untick Use multipart/form-data box in the HTTP Request sampler
Remove issueDetail parameter name and put it to the end of "path"
Change Content-Type header value to application/json
Authorization header value might need to be correlated if the token life span is short
More information: Testing SOAP/REST Web Services Using JMeter
Scenario: I've two post requests in jmeter one is used for token generation which has content type "application/x-www-form-urlencoded" and second is used for xyz operation by using that token has content type application/json, how can i perform this in jmeter?
For 1st request just make sure to choose POST value from the "Method" dropdown and make sure that Use multipart/form-data box is not ticked
JMeter will automatically send application/x-www-form-urlencoded request header for POST
For 2nd request add a HTTP Header Manager as a child and configure it to send the required Content-Type header
I have a simple thread group with HTTP requests as below:
Do Login - POST request
grab the authorization bearer token
Get eventId - GET request
This is a simple HTTP GET request like this http://server_ip:8080/rest/v1/events/1234567
Pass the authorization bearer token in HTTP Header Manager
When I run the above, the Login post request goes through fine. I get a 200 OK and the response header ad message looks fine.
But the 'Get eventId' request fails and returns a 400 Bad Request.
However when I start JMeter to go through the proxy like below, the 'Get eventId' request returns a 200 OK and the response looks as expected.
jmeter.bat -H 127.0.0.1 -P 8888
I am not sure what I am doing wrong?
As per 400 Bad Request status code description:
The HyperText Transfer Protocol (HTTP) 400 Bad Request response status code indicates that the server could not understand the request due to invalid syntax.
Most likely you need to add HTTP Header Manager to send Content-Type header with the value of application/json (or whatever MIME type server expects).
If this is not the case - inspect what is being sent in both cases using View Results Tree listener and amend JMeter configuration so requests would look exactly the same (apart from dynamic token)
I have recorded a native app in jmeter. It shows one auto-generated 'Authorization Manager' where username is appearing as '${Auth_Login}' and password as ${Auth_password}.
I am running the script but the response is appearing as :
"{"error":"No authorization header."}"
Please help me out to resolve this issue.
You should extract the token which returns from the first response using a post processor (i.e regular expression extractor).
Now add this token to the next request's header manager like this:
Name: Authorization
Value: ${Token}
Note: you should check the request header using traffic capturing tool i.e fiddler, because these names might not be the same also the token sometimes looks like this Bearer ${Token}
See using regex with jmeter for more information on regular expression extractor.