Gatling:RawFileBody没有输出文本

时间:2015-04-14 17:02:30

标签: scala gatling

我是Gatling的新手,正致力于编写我的第一个场景。我无法让RawFileBody工作。我通过提琴手引导所有流量,这样我就可以看到发生了什么,文件内容没有输出到请求体。使用StringBody工作正常但我不喜欢将它用于非常大的JSON有效负载。

我已经检查过该文件位于“... \ gatling \ gatling-charts-highcharts-bundle-2.1.4 \ user-files \ bodies”目录中,我尝试过使用绝对路径,我我试过添加asJSON。我已将日志级别设置为跟踪并且没有看到任何错误或警告,但请求正文仍为空。这是脚本的相关部分(忽略任何小错误,因为我必须删除大量专有代码):

import io.gatling.core.scenario.Simulation
import io.gatling.core.Predef._
import io.gatling.http.Predef._

import java.util.UUID

class Scenario1 extends Simulation {

  val uri1 = "http://somehost"

  val httpProtocol = http
    .baseURL("http://somehost")
    .proxy(Proxy("localhost", 8888).httpsPort(8888))
    .inferHtmlResources()
    .acceptHeader("application/json")
    .contentTypeHeader("application/json")

  val header = Map("Some" -> "proprietary-header")

  object Foo {
    val bar = exec(http("bar")
      .post(uri1 + "/app/myservice")
      .headers(header)
      .body(RawFileBody("my_request.txt")))
  }

  val scn = scenario("scenario1").exec(Foo.bar)

  setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

你在http部分设置了baseURL,然后在.post部分再次添加它。 Post默认使用baseURL并添加您指定的任何内容。所以你似乎在呼叫http://somehosthttp://somehost/app/myservice。除此之外你应该没问题,但添加.asJSON并确实使用绝对路径。祝你好运。