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?
Default value
set? If not, add it. That way you can identify whether Regex post-processor really not finding your regex (and thus will use default value), or it's not running at all (and thus you will still see${access_token}
unresolved. If regex is not found, there must be some mistake in regex extractor: check Apply To and Field To Check fields, make sure they are correct, maybe configure it again from scratch. – Kiril S.