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.
After some hours search, I cannot find a possibility to extract the http response body as a byte array:
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)
Alternatively it would also be fine if I could set a value in getFirstRequest, that I can reuse in 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...
}
I think you can try something like this :
.check(status.is(200), bodyBytes.saveAs("responseBody"))
This will save the body of the response in the virtual user's session.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.