【问题标题】:Gatling2: Get response body as byte arrayGatling2:以字节数组形式获取响应正文
【发布时间】:2014-05-15 23:16:00
【问题描述】:

我想发送一个请求,并会收到一个 byte[] 正文响应。基于这个 byte[] 响应,我想提取一个值(使用 protobuf)并在另一个请求中重用这个值。

经过几个小时的搜索,我找不到将 http 响应正文提取为字节数组的可能性:

   val httpConfig = http
    .baseURL("http://www.whatever.com")

   val request = exec(http("FirstRequest")
    .post("/message")
    .body(new ByteArrayBody((session: Session) => getFirstRequest(session)))
      .check(status.is(200), ???getByteResponse???))

   val response = exec(http("SecondRequest")
    .post("/message")
    .body(new ByteArrayBody((session: Session) => getSecondRequest(session)))
    .check(status.is(200), ???getByteResponse???))

   val scn = scenario("Request").exec(request,response)

  setUp(scn.inject(atOnce(1 user)))
    .protocols(httpConfig)

另外,如果我可以在 getFirstRequest 中设置一个值,我可以在 getSecondRequest 中重用它也可以:

private def getFirstRequest(session: Session): Array[Byte] = {

    ... setting a session attribute ... (long)

    ... some protobuf stuff returning a byte array ...  

  }

  private def getSecondRequest(session: Session): Array[Byte] = {
      var value= session("value").as[Long]

    ... some protobuf stuff using value from session and then returning byte array...
  }

【问题讨论】:

    标签: scala gatling


    【解决方案1】:

    我想你可以试试这样的:

    .check(status.is(200), bodyBytes.saveAs("responseBody"))
    

    这会将响应的正文保存在虚拟用户的会话中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-05
      • 1970-01-01
      • 2015-12-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多