问题
I have run Login sampler and I get the result like this
[Login Sampler Result Data][1]
Here, I want to take
"access_token":"91kLM68tdMBoDFRURArvdmwYgWV9Nr2sHYDwivTM"
and save the "91kLM68tdMBoDFRURArvdmwYgWV9Nr2sHYDwivTM" to a variable, then parse that to HTTP Header Manager
here where I want to parse the variable
I am using JMeter version 2.13
Help me please.
回答1:
First of all add an regular expression extractor under login sampler (right click on login sampler --> Add--> Post Processor--> Regular expression extractor).
After that enter details as shown in the below snapshot where
Reference Name: access_token
regular expression: access_token":"(.*?)"
Template $1$
MatchNo:1
then pass access_token variable inside header manager as ${access_token}
Please refer below snapshot for better understanding
回答2:
What Kaushlendra Jha is right! ...just don't forget to extract it from the right place.
For example:
If you are calling the login restful webservice (API) directly, most likely the access token will be returned in the Body.
That said, in the "Regular Expression Extractor" post processor you should leave the "Field to check" property as it is (Body).
In case you are simulating the hole http call to your login page (http request), the access token is very likely to be returned in http response header instead.
If that is the case, make sure to select "Response Headers" radio button of the "Field to check" section of the "Regular Expression Extractor" post processor.
来源:https://stackoverflow.com/questions/35935934/how-to-get-response-data-and-parse-it-to-http-header-manager-in-jmeter