I'm trying to send a json body to my Api using Gatling, but I keep getting error 400 because it cannot unmarshall the body i'm sending:
private val authHeaders = Map(
"Accept" -> "application/json, text/javascript, */*; q=0.01",
"Authorization" -> "Bearer ${access_token}"
)
var requestBody: Body with (Expression[String]) =StringBody("{ \"productId\": " +
product1 + ", \"qty\": "+ 1 +" , \"storeId\": "+ storeId + "}")
var addToCart: ChainBuilder = exec(http("addToCart")
.post(addToCartUrl)
.headers(authHeaders)
.body(requestBody)
.check(bodyString.saveAs("body"))
)
In the Gatling logs I can read that I'm sending this kind of request:
HTTP request:
POST ....
headers:
Accept: application/json, text/javascript, */*; q=0.01
Authorization: Bearer ....
cookie: ROUTE=....
host: .....
content-length: 53
cookies:
ROUTE=...., path=/, secure, HTTPOnly, SameSite=None
body:StringChunksRequestBody{contentType='null', charset=UTF-8, content={ "productId": XXXX, "qty": 1 , "storeId": XXXX}}
I don't think I'm creating the correct body, Is there a way to send only { "productId": XXXXX, "qty": 1, "storeId": XXXXXX} as body? I might have put the contentType in the wrong way, what is the right order?. Thanks for your collaboration!
Are you sure product1
and storeId
are numbers and not Strings? Otherwise, they must be wrapped with double quotes, which they currently aren't.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.