title: Gatling2: Get response body as byte array
body: <p>I want to send a request and will receive a byte[] body response. Based on this byte[] response I want to extract a value (using protobuf) and the reuse this value in another resquest.</p>
  
  <p>After some hours search, I cannot find a possibility to extract the http response body as a byte array:</p>
  
  <pre><code>   val httpConfig = http
      .baseURL("http://www.whatever.com")
  
     val request = exec(http("FirstRequest")
      .post("/message")
      .body(new ByteArrayBody((session: Session) =&gt; getFirstRequest(session)))
        .check(status.is(200), ???getByteResponse???))
  
     val response = exec(http("SecondRequest")
      .post("/message")
      .body(new ByteArrayBody((session: Session) =&gt; getSecondRequest(session)))
      .check(status.is(200), ???getByteResponse???))
  
     val scn = scenario("Request").exec(request,response)
  
    setUp(scn.inject(atOnce(1 user)))
      .protocols(httpConfig)
  </code></pre>
  
  <p>Alternatively it would also be fine if I could set a value in getFirstRequest, that I can reuse in getSecondRequest:</p>
  
  <pre><code>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...
    }
  </code></pre>