简体   繁体   English

为每个JMeter HTTP请求添加会话ID

[英]Add Session ID to each JMeter HTTP request

For my JMeter test, I would like all threads in the test to use one shared session id. 对于我的JMeter测试,我希望测试中的所有线程都使用一个共享会话ID。 The session id is known before I start the test job. 在开始测试作业之前,会话ID已知。 How do I specify a specific JSessionId for my JMeter test? 如何为JMeter测试指定特定的JSessionId?

I've tried appending a JSessionId parameter in the HTTP Cookie Manager (under user-defined cookies), in the HTTP Request Defaults (under send parameters with the request), and I tried adding a 'HTTP URL Re-writing Modifier' from the Pre-Processor tab under the Recording Controller. 我尝试在HTTP Cookie管理器中(在用户定义的cookie下),在HTTP请求默认值中(在带有请求的发送参数下)附加一个JSessionId参数,我尝试添加一个'HTTP URL重写修饰符'录制控制器下的预处理器选项卡。 None of these have worked. 这些都没有奏效。 Which step is the best way to set a fixed session id for my JMeter test? 哪一步是为我的JMeter测试设置固定会话ID的最佳方法?

You need to add jp@gc-JSON Path Extractor in HTTP request, the particular HTTP request which is generating session id in its response data . 您需要在HTTP请求中添加jp@gc-JSON Path Extractor ,这是在其响应数据中生成会话ID的特定HTTP请求。 If response is like: 如果回复如下:

{"sessionId":"f5b06970-f00f-4b44-89c8-305738e19cba","loginDate":1483599209337} 

In JSON path extractor add: 在JSON路径提取器中添加:

  1. Variable name - session (variable in which session id will be stored) 变量名 - 会话(将存储会话ID的变量)
  2. JSON Expression - $.sessionId (this will vary according to the JSON response) JSON表达式 - $.sessionId (这将根据JSON响应而有所不同)
  3. Default Value - NOT_FOUND 默认值 - NOT_FOUND

Now the next step is to use this variable named "session". 现在,下一步是使用名为“session”的变量。 You can use it in your HTTP request for which you need to pass session id under HTTP header manager as x-auth-token = ${session} 您可以在HTTP请求中使用它,您需要在HTTP头管理器下传递会话ID,如x-auth-token = ${session}

You were correct when you tried to use the HTTP Cookie Manager , this should do what you need. 当您尝试使用HTTP Cookie管理器时 ,您是正确的,这应该可以满足您的需求。

Probably, it didn't work for one of two reasons: 可能由于以下两个原因之一而无效:

You either have the Cookie Manager in the wrong place. 您要么将Cookie管理器放在错误的位置。 To affect all requests it should be at the root of the Test Plan or Thread Group. 要影响所有请求,它应该位于测试计划或线程组的根目录下。

Or, more likely, you didn't specify all the required values properly when you added the User Defined Cookie. 或者,更有可能的是,在添加用户定义Cookie时,未正确指定所有必需值。 This can be tricky to get working; 开始工作可能很棘手; have you made sure you're not using 'http://' in the domain field? 你确定你没有在domain字段中使用'http://'吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM