简体   繁体   English

如何将动态标头传递给 jMeter 中的 Http 请求?

[英]How to pass dynamic headers to the Http Request in jMeter?

There is a initial request going to the server which should retrieve the CSRF token and use that token id in post request header.有一个发送到服务器的初始请求,该请求应该检索 CSRF 令牌并在 post 请求标头中使用该令牌 ID。

if that does not happen any POST requests to the server will return that error.如果没有发生任何 POST 请求到服务器将返回该错误。

在此处输入图片说明

In the above screen shot, where token is the request to get the CSRF token Id, If I run the test this will generate one dynamic random token ID.在上面的屏幕截图中,token 是获取 CSRF 令牌 ID 的请求,如果我运行测试,这将生成一个动态随机令牌 ID。 But I need to pass the generated token ID in the post request through Header Manager.但是我需要通过 Header Manager 在 post 请求中传递生成的令牌 ID。 How can it possible.怎么可能。 If yes, Can any one suggest some way to do that.如果是的话,任何人都可以提出某种方法来做到这一点。

我通过使用用户定义的变量和正则表达式提取器将参数从一个请求采样器传递到另一个来解决它。

In the firs request add a postprocesor of the request.在第一个请求中添加请求的后处理器。 if the response is un json format user json Extractor, in json Extractor define a variable that read the token如果响应是 un json 格式用户 json Extractor,则在 json Extractor 中定义一个读取令牌的变量

In the second request add a header Manager an refer varaible declare in json Extractor in the following way in value cell, ${variable}在第二个请求中,在值单元 ${variable} 中按以下方式在 json Extractor 中添加标头管理器和引用变量声明

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

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