【问题标题】:Gatling request body as bytearrayGatling 请求正文为字节数组
【发布时间】:2020-03-29 20:49:36
【问题描述】:
val scn = scenario("gatling test").
    feed(circularfeeder.circular)
    .exec(http("request")
      .post(endpoint)
      .header("Content-Type", "application/json")
      .header("Accept-Encoding", "charset=UTF-8")
      .body(StringBody("""${request}"""))
      .check(status.is(200))

上面的代码用于将每个循环馈送数据作为字符串发送到请求的主体。假设如果我想在正文中作为字节数组而不是字符串发送,我该如何修改.body(StringBody("""${request}"""))

代码.body(ByteArrayBody(getBytesData("""${request}"""))) 不起作用。有什么建议吗?

【问题讨论】:

    标签: scala gatling scala-gatling gatling-plugin


    【解决方案1】:

    选项 1

    request 字符串上调用getBytes 方法并将其传递给ByteArrayBody

    .body(ByteArrayBody { session => 
      session("request")
        .validate[String]
        .map(s => s.getBytes(StandardCharsets.UTF_8)) 
    })
    

    选项 2

    转换您从馈送器获得的原始数据。

    val circularfeeder = csv("myFile.csv").convert {
      case ("request", string) => string.getBytes(StandardCharsets.UTF_8)
    }
    ...
    .body(ByteArrayBody("${request}"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-05
      • 2021-02-02
      • 2012-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-30
      • 1970-01-01
      相关资源
      最近更新 更多