您可以在创建 http 协议时直接配置默认标头,例如
val httpConf = http
// Here is the root for all relative URLs
.baseURL("http://computer-database.gatling.io")
// Here are the common headers, via specialized methods
.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")
// More generic methods are available too
.header("foo", "bar") // to set one header
.headers(Map("foo" -> "bar", "baz" -> "qix")) // to set a bunch of headers
val scn = scenario("Scenario Name")
.exec(http("request_1").headers(...) // This is for single request, but you know it already
.get("/")) // etc...
setUp(scn.inject(atOnceUsers(1)).protocols(httpConf))
有关更多信息,请参阅文档Http Headers