如何在查询参数中添加 JSON from "Body"?

How to add JSON from "Body" in the query parameter?

我正在尝试向 SQS 队列发送消息。我已正确设置所有内容。 我使用的是 fifo 队列,所以我的 post 字符串如下所示:

https://queuename?Action=SendMessage&MessageBody=TEST&MessageGroupId=6&MessageDeduplicationId=6

以上工作正常,消息正文为 TEST,但是,我想以 JSON 格式发送数据 在正文选项卡中,我将有效负载格式化为 JSON。如何将 JSON 值作为变量放入 MessageBody 字段?

第 1 步。将 json 保存在变量中

const body = {
    "key": "value"
}

//encoded the special character to make it valid in URL
const payload = encodeURIComponent(JSON.stringify(body))

//Put it in an environment variable
pm.environment.set("payload", payload)

第 2 步:在 URL

中使用此变量
https://queuename?Action=SendMessage&MessageBody={{payload}}&MessageGroupId=6&MessageDeduplicationId=6