How to get Response Data and parse it to HTTP Header Manager in JMeter

寵の児 提交于 2019-12-12 18:27:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!