在 Gatling 中传递多个标题
Posted
技术标签:
【中文标题】在 Gatling 中传递多个标题【英文标题】:Passing Multiple Headers in Gatling 【发布时间】:2021-08-31 08:17:24 【问题描述】:我是 Gatling 工具的新手,尝试从另一个文件传递多个标头值,但在编译时遇到错误。
代码:
val header0 = List(Map(
"Ocp-Apim-Subscription-Key" -> TestParameters.Keyvalue,
"UserId" -> TestParameters.UserID
))
错误:
ingInformation.scala:22:13: type mismatch;
found : scala.collection.immutable.Map[String,java.io.Serializable]
required: Map[String,String]
.headers(header0)
^
【问题讨论】:
【参考方案1】:为什么要把header0
做成一个List[Map[String, String]]?
应该是一个 Map[String, String]:
val header0 = Map(
"Ocp-Apim-Subscription-Key" -> TestParameters.Keyvalue,
"UserId" -> TestParameters.UserID
)
此外,正如documentation 中所述,标头值必须是字符串。因此,如果TestParameters.Keyvalue
或TestParameters.UserID
是其他任何东西,例如数字,您必须转换它们,例如使用toString
。
【讨论】:
found : scala.collection.immutable.Map[String,java.io.Serializable] required: Map[String,String] .headers(header0) ^ 仍然面临同样的错误 @SriramRAJASEKARAN 你的钥匙类型有问题。查看密钥类型 - 有java.io.Serializable
但应该有 String
我已经更新了我的答案。是的,标头值必须是字符串。我猜你是在混合字符串和数字。以上是关于在 Gatling 中传递多个标题的主要内容,如果未能解决你的问题,请参考以下文章
Gatling - 用 session 实现关联 传递 token 值
如何从 cookie 中保存 XSRF 令牌并将其传递给 Gatling 的下一个请求标头中的服务器
如何在 Gatling 负载测试中为多个虚拟用户使用单个 OAuth2.0 令牌