简体   繁体   English

只获得加特林的响应主体

[英]Get only the response body in gatling

I need to parse an id from the response body and send it in the next request body in gatling for session based users. 我需要从响应主体解析一个id,然后在下一个请求体中将其发送给基于会话的用户。 If anyone has an idea about that, please share it. 如果有人对此有所了解,请分享。

I have used the .check(regex()) and .saveAs method, but that saves the data in session, for which I need to do a complex parsing which I dont want. 我使用了.check(regex()).saveAs方法,但这会将数据保存在会话中,为此我需要进行一些我不想要的复杂解析。

Save it in the session using: 使用以下方法将其保存在会话中

.check(jsonPath("$.id").saveAs("id"))

To send it in the next request, extract it first using 要在下一个请求中发送它,请先使用提取它

val id = session.get("id").as[String]

Alternatively, if you want to use it in the next request in the chain: 或者,如果要在链中的下一个请求中使用它:

def get(token: String, org: String): ChainBuilder = {
    val url = MY_SERVICE_URI + "/${id}"
    exec(http("Get something")
      .get(url)
      .header(HttpHeaders.AUTHORIZATION, token)
      //etc'

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

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