在PUT请求中发送JSON

时间:2019-06-11 13:50:46

标签: gatling scala-gatling

以下过程(取自https://gatling.io/docs/2.3/http/http_request/,已删除.toJSON,因为它不存在),但未向REST API添加条目:

class TestREST extends Simulation {
  val httpProtocol = http
    .baseUrl("http://127.0.0.1:5000") // Here is the root for all relative URLs

  val scn = scenario("UploadMany") // A scenario is a chain of requests and pauses
    .exec(http("request_1")
      .put("/")
      .body(StringBody("""{
            "text":"lalala", "title": "hello world", "date": "12346"}"""))
      .check(status.is(200))
    )

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

}

如何通过加特林将JSON数据添加到.put请求中?

1 个答案:

答案 0 :(得分:1)

我从https://gatling.io/docs/2.3/http/http_request/的示例中删除了.asJSON,因为它失败了。在3.1中,此方法已重命名为(大写).asJson,因此,以下更改对其进行了修复:

  .body(StringBody("""{
        "text":"lalala", "title": "hello world", "date": "12346"}""")).asJson