2017-09-13 90 views
1

我在scala中使用gatling ver 2.3.0。发送请求获取从重定向到变量的URL后可能吗?例如我请求192.168.1.30:8080/,并且此链接将我重定向到192.168.1.30:8080/token/123,我可以获得/ token/123吗?我想这个代码,但出现错误header.find.exists,一无所获,但菲德勒我看到这个标题在scala中加特林如何从重定向中获取url

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 
}) 
+0

不太清楚,如果这回答你的问题,但[加特林如下自动重定向(http://gatling.io/docs/current/HTTP/http_protocol /#后续重定向) – Phonolog

回答

0

我知道什么是错的重定向这是回答我的问题: 1)我要补充到httpConf .disableFollowRedirect和。检查(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 
    })