How to pass base64 encoded variable value into .Json file

Hello,

I’m getting “400” error response from Post request while passing base64 encoded variable value to .json file. Below is code snippet.

val encodedMessage = Base64.getEncoder.encode(sourceCodeBytes)
val base64Msg = new String(encodedMessage)

In post request:
.body(ElFIileBody(“apipackage1/recordedsimulationapi/0000_request.json”))

In 0000_request.json file:
{“messages”:[{“data”:“#{base64Msg}”,“attributes”:{“GaSell”: “CTY.DK”,“contentMsgId”:“1”}}]}

Can anyone pls help on this issue.

Appreciate your quick response.

Thanks.

You have to prepare the encoded String upfront with the Session API. Please read the documentation.

Thanks for your response Stephane!

I tried it as per the documentation. May be i’s wrong. I’m completely new to Gatling.

Can you pls send code snippet for how to prepare the encoded String upfront with the Session API.

Appreciate for your quick response.

Thanks.

Hi Stephane,

Still getting 400 error while sending payload to GCP pub/sub topic.
Below is http response from post request. In body, i’m sending correct base64 encoded values. But still giving bad request error. Can you pls let me know how to send the payload to GCP pub/sub topic.

body:ByteArrayRequestBody{contentType=‘application/json’, content (Base64)=eyJtZX

HTTP response:
status:
400 Bad Request
headers:
Vary: X-Origin
Vary: Referer
Content-Type: application/json; charset=UTF-8
Date: Thu, 17 Aug 2023 10:59:13 GMT
Server: ESF
Cache-Control: private
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Alt-Svc: h3=“:443”; ma=2592000,h3-29=“:443”; ma=2592000
Accept-Ranges: none
Vary: Origin,Accept-Encoding
Transfer-Encoding: chunked

body:
{
“error”: {
“code”: 400,
“message”: “Invalid value at ‘messages[0].data’ (TYPE_BYTES), Base64 decoding failed for "#{xyz}"”,
“status”: “INVALID_ARGUMENT”,
“details”: [
{
@type”: “type.googleapis.com/google.rpc.BadRequest”,
“fieldViolations”: [
{
“field”: “messages[0].data”,
“description”: “Invalid value at ‘messages[0].data’ (TYPE_BYTES), Base64 decoding failed for "#{xyz}"”
}
]
}
]
}
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.