How to conform response of one request and pass to another request

Hi All,

Can anyone please help me on how to get response of the request and send it to another request. Please find below code.

.exec(http(“Create USer”)
.post(""“Urlxxxx”"")
.body(StringBody("""{“email":"sample@gmail.com”}"""))
.check(headerRegex(“Location”, “(.*)”).saveAs(“userId”))) // here i am saving this location value in üserId variable

// System.out.println("UserID: " + userId+ “\n”) // i tried to print like this, no use

//exec(
(s:Session) => println(s.getAttribute(“userId”)) // tried this also, but no use to conform what i am getting in UserId
)

val scn1 = scenario(“Identity”)
.exec(http(“request_0”)
.post("""/urlxxxx""")
.body(StringBody("""{
“username”:“anitha156”,
“password”:“anitha56”,
“userId”:"${userId}", // passing that userid in this request.
}""")))

}

Please help me on how to conform the value i am getting in Userid and how to pass this to next request???

To print, you can do this.

`
exec{ session =>
println(session(“userid”).as[String]
session
}

`

You can also check the logs, which will show you both request and response. Uncomment Trace in logback.xml.

Hi Abhinav,

Thank you for your reply… I tried the below code, but no use. Where i have to place this code? and can you please tell me how to pass this response value to next request?

If i want to see the complete response body , what are the changes i have to do in logback.xml.?

Regards,
Anitha.

Anitha,

You can use exec in scenario chain bulder.

val scn1 = scenario("Identity").exec{ session => println(session(“userid”).as[String] session }`.exec(http(“request_0”)
.post("""/urlxxxx""")
.body(StringBody("""{
“username”:“anitha156”,
“password”:“anitha56”,
“userId”:"${userId}", // passing that userid in this request.

}""")))

}

`