3

I'm trying to add a POST HTTP method to my AWS API Gateway. I'm using SAM framework with Python.

I find that there is a difference in the "body" of the response when it is generated from my desktop (curl or postman) and the AWS API Gateway 'TEST'

Right now, the "POST" command only prints the 'event' object received by the lambda_handler. (I'm using an object to store the event as you can see below)

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

When I'm using the 'TEST' option of the API Gateway console, with the input:

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

I receive the following output:

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

However, when I'm sending the curl (or postman) request:

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

I get the following response:

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

Why do you think there is a difference between the two tests?

4

1 回答 1

2

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

反应是一样的。后一个响应是第一个响应的 Base64 编码标记。

于 2018-11-12T05:39:18.433 回答