Amazon API 网关:当通过 Postman 调用 API 时,响应 body 没有转换?
Amazon API Gateway : response body is not transformed when the API is called via Postman?
通过 AWS API 网关控制台执行测试时,我看到 Lambda 函数的输出响应已正确转换:
{
"type" : "",
"message" : "",
"request-id" : ""
}
查看下面的日志:
Tue Sep 06 14:46:06 UTC 2016 : Endpoint request body after transformations: {}
Tue Sep 06 14:46:06 UTC 2016 : Endpoint response body before transformations: {"errorMessage":"501stef"}
Tue Sep 06 14:46:06 UTC 2016 : Endpoint response headers: {x-amzn-Remapped-Content-Length=0, x-amzn-RequestId=a4540f42-7440-11e6-90ce-214b29fcde38, Connection=keep-alive, Content-Length=26, Date=Tue, 06 Sep 2016 14:46:06 GMT, Content-Type=application/json}
Tue Sep 06 14:46:06 UTC 2016 : Method response body after transformations: {
"type" : "",
"message" : "",
"request-id" : ""
}
Tue Sep 06 14:46:06 UTC 2016 : Method response headers: {Content-Type=application/json}
Tue Sep 06 14:46:06 UTC 2016 : Successfully completed execution
Tue Sep 06 14:46:06 UTC 2016 : Method completed with status: 501
然而,当通过 Postman 使用 headers 调用 API 时:
Content-Type : application/json
Accept : application/json
没有发生输出转换,输出 JSON 消息只是:
{
"errorMessage": "501stef"
}
与 部分相关,但本文讨论的是 Request。
API 网关控制台上的测试调用与使用 API 网关的实际调用之间的区别是测试调用始终假设 content-type 是 "application/json" 并接受 "application/json"。当您通过 Postman 调用时,您可能希望通过 header accept 传递 "application/json"。
在外部可见更改之前,您需要部署 API !
通过 AWS API 网关控制台执行测试时,我看到 Lambda 函数的输出响应已正确转换:
{
"type" : "",
"message" : "",
"request-id" : ""
}
查看下面的日志:
Tue Sep 06 14:46:06 UTC 2016 : Endpoint request body after transformations: {}
Tue Sep 06 14:46:06 UTC 2016 : Endpoint response body before transformations: {"errorMessage":"501stef"}
Tue Sep 06 14:46:06 UTC 2016 : Endpoint response headers: {x-amzn-Remapped-Content-Length=0, x-amzn-RequestId=a4540f42-7440-11e6-90ce-214b29fcde38, Connection=keep-alive, Content-Length=26, Date=Tue, 06 Sep 2016 14:46:06 GMT, Content-Type=application/json}
Tue Sep 06 14:46:06 UTC 2016 : Method response body after transformations: {
"type" : "",
"message" : "",
"request-id" : ""
}
Tue Sep 06 14:46:06 UTC 2016 : Method response headers: {Content-Type=application/json}
Tue Sep 06 14:46:06 UTC 2016 : Successfully completed execution
Tue Sep 06 14:46:06 UTC 2016 : Method completed with status: 501
然而,当通过 Postman 使用 headers 调用 API 时:
Content-Type : application/json
Accept : application/json
没有发生输出转换,输出 JSON 消息只是:
{
"errorMessage": "501stef"
}
与
API 网关控制台上的测试调用与使用 API 网关的实际调用之间的区别是测试调用始终假设 content-type 是 "application/json" 并接受 "application/json"。当您通过 Postman 调用时,您可能希望通过 header accept 传递 "application/json"。
在外部可见更改之前,您需要部署 API !