aws api 网关测试和 curl 中请求正文的差异

Difference in request body in aws api gateway test and curl

我正在尝试向我的 AWS API 网关添加一个 POST HTTP 方法。我在 Python 中使用 SAM 框架。

我发现从我的桌面(curl 或邮递员)和 AWS API 网关生成的响应 "body" 存在差异 'TEST'

现在,"POST" 命令仅打印 lambda_handler 接收到的 'event' 对象。 (我正在使用一个对象来存储事件,如下所示)

def add(self):
    response = {
        "statusCode": 200,
        "body": json.dumps(self._event)
    }
    return response

当我使用 API 网关控制台的 'TEST' 选项时,输入:

{"username":"xyz","password":"xyz"}

我收到以下输出:

{
 "body": "{\"username\":\"xyz\",\"password\":\"xyz\"}",
<the rest of the response>
}

但是,当我发送 curl(或 postman)请求时:

curl --header "Content-Type: application/json"   --request POST   --data '{"username":"xyz","password":"xyz"}' <aws api gateway link>

我收到以下回复:

{
"body": "eyJ1c2VybmFtZSI6Inh5eiIsInBhc3N3b3JkIjoieHl6In0="
<the rest of the response>
}

为什么您认为这两个测试之间存在差异?

Curl 和 Postman 似乎会自动对您的身份验证凭据进行 Base64 编码。

答案是一样的。后一个响应是第一个响应的 Base64 编码令牌。