我在scala中使用gatling ver 2.3.0。发送请求后是否可以从重定向到变量获取URL?例如我请求192.168.1.30:8080/并且此链接将我重定向到192.168.1.30:8080/token/123,我可以获得/ token / 123吗?我试过这个代码,但发生错误header.find.exists,发现什么,但在Fiddler我看到这个标题
_renderItem
答案 0 :(得分:1)
我知道重定向有什么问题这是我的问题的答案: 1)我应该将httpConf .disableFollowRedirect和.check(status.is(302))添加到场景
val httpConf = http
.baseURL("192.168.1.30:8080") // Here is the root for all relative URLs
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") // Here are the common headers
.acceptEncodingHeader("gzip, deflate")
.acceptLanguageHeader("en-US,en;q=0.5")
.userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")
.disableFollowRedirect
val scn = scenario("SCENARIO2")
.exec(http("open")
.get("/")
.check(status.is(302))
.check(header("Location").saveAs("url")))
.exec(session => {
val urlN = session.get("url").asOption[String]
print(urlN.getOrElse("nothing"))
session
})