8

我正在尝试将 Amazon API 网关与 Lambda 函数集成。虽然我成功地实现了,但是当我尝试使用 curl 时它失败了。

设置了 Lambda 方法、API 网关集成以及集成请求下的模板映射。

当我从控制台运行“测试”时,它工作正常

Execution log for request test-request 
Wed Nov 04 07:27:30 UTC 2015 : Starting execution for request: test-invoke-request
Wed Nov 04 07:27:30 UTC 2015 : API Key: test-invoke-api-key
Wed Nov 04 07:27:30 UTC 2015 : Method request path: {service=xml}
Wed Nov 04 07:27:30 UTC 2015 : Method request query string: {}
Wed Nov 04 07:27:30 UTC 2015 : Method request headers: {}
Wed Nov 04 07:27:30 UTC 2015 : Method request body before transformations: Articletext
Wed Nov 04 07:27:30 UTC 2015 : Endpoint request body after transformations: {
  "prog" : "xml",
  "content" : "Articletext",
  "test" : "{path={service=xml}, querystring={}, header={}}"
}

但是当我尝试通过 curl 访问它时,它无法在转换后创建正确的主体

curl -X POST https://aaaaaaa.execute-api.us-west-2.amazonaws.com/beta/apitest/xml -H "Content-Type: application/x-www-form-urlencoded; charset=UTF- 8" --data-binary "文章文本"

Starting execution for request: 
Method request path: {service=xml}
Method request query string:
{}
Method request body before transformations: Articletext
Endpoint request body after transformations: Articletext
Endpoint response body before transformations:
{
    "Type": "User",
    "message": "Could not parse request body into json."
}

任何人都可以向我建议缺少的部分吗?

4

2 回答 2

4

就我而言,问题是我没有部署 API,因此没有更新它以供外部使用。请参阅Amazon API Gateway:通过 Postman 调用 API 时响应正文未转换?

于 2016-09-08T12:14:07.280 回答
3

请确保您在集成请求模板中定义的内容类型。

你可以试试这个 curl 命令。

curl -X POST https://aaaaaaa.execute-api.us-west-2.amazonaws.com/beta/apitest/xml -H "Content-Type: application/json" --data-binary "Articletext"

于 2016-05-07T17:33:58.627 回答