且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 Jmeter xpath 提取器获取 oauth 令牌并在其他 Http 请求的路径中使用它

更新时间:2022-10-31 18:47:57

您可以使用

您也可以使用

What should be the Regular expression if I want to extract the value for access token, So that i can use it in Path of other Http request ie like access_token=93ee29b4-74dc-4uu7-8e10-6eac6845511b from below http response.

{
   "access_token":"93ee2tum-1234-56789-8e10-6eac684551tum",
   "token_type":"Bearer",
   "expires_in":3600,
   "scope":"test"
}

I have given regular expression as

"access_token":"([^"]+)"

And also where can i check the value of regular expression I am getting

You can test your Regular Expressions using View Results Tree listener in RegExp Tester mode like:

Also you can use Debug Sampler to see the associated JMeter Variables. See How to Debug your Apache JMeter Script article for details.


Starting from JMeter 3.0 it's more handy to use JSON Path PostProcessor, in that case the relevant JSON Path Expression would be as simple as:

$.access_token