【问题标题】:Gatling in scala how to get url from redirectscala中的加特林如何从重定向中获取url
【发布时间】:2018-02-21 22:57:54
【问题描述】:

我在 scala 中使用 gatling 版本 2.3.0。发送请求后是否有可能从重定向到变量获取 url?例如我请求 192.168.1.30:8080/ 并且此链接将我重定向到 192.168.1.30:8080/token/123,我可以获得 /token/123 吗?我尝试使用此代码,但出现错误 header.find.exists,除了在 Fiddler 中什么都没有找到,我看到了这个标题

 val httpConf = http
        .baseURL("http://192.168.1.30:8080")
 .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
            .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")

val scn = scenario("SCENARIO2")
.exec(http("open")
  .get("/")
  .check(header("Location").saveAs("url")))
.exec(session => {
  val urlN = session.get("url").asOption[String]
  print(urlN.getOrElse("nothing"))
  session
})

【问题讨论】:

标签: scala gatling


【解决方案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
    })

【讨论】:

    猜你喜欢
    • 2020-06-18
    • 1970-01-01
    • 1970-01-01
    • 2021-03-28
    • 2013-06-06
    • 2016-12-11
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多