我需要发送一个包含两个键的表单数据主体的 post 请求:
justificatifs : text (json)
文档:文件(在我的情况下为 pdf 或 jpg)。 我怎样才能通过加特林做到这一点? 我的代码:
.exec(http("add...")
.post("/...")
.header("Authorization","Bearer " +"${accessToken}")
.header("Content-Type", "multipart/form-data")
.formParam("justificatif", ".src/...Doc.json")
.formupload("documents",".src/...identite-test.pdf")
.check(status is 201))
谢谢!
答案 0 :(得分:0)
您可以使用 RawFileBodyPart https://gatling.io/docs/gatling/reference/current/http/request/#multipart-form
exec(http("Upload document")
.post("""/updocs/""")
.formParam("retention", "42 days")
.formParam("name", "file.pdf")
.bodyPart(
RawFileBodyPart("file", "file.pdf")
.contentType("application/pdf")
.fileName("file.pdf")
).asMultipartForm
.check(status.is(201)))