lambda - 无法在 Serverless .net core web api 中映射 POST API 的请求参数
问题描述
我正在尝试在 Visual Studio Serverless Web api 项目中编写一些 api。我面临的问题是如何在 Post 请求中映射参数:
[HttpPost]
public async Task<IActionResult> Login([FromBody]LoginRequest request)
{
.......
}
此 API 将托管在 API Gateway 上。如何操作 body 属性以便可以映射 LoginRequest 对象?
{
**"body": "{\"test\":\"body\"}", // map LoginRequest here ?**
"resource": "/{proxy+}",
"path": "/path/to/resource",
"httpMethod": "POST",
"queryStringParameters": {
"foo": "bar"
},
"pathParameters": {
"proxy": "path/to/resource"
},
"stageVariables": {
"baz": "qux"
},
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, sdch",
"Accept-Language": "en-US,en;q=0.8",
"Cache-Control": "max-age=0",
"CloudFront-Forwarded-Proto": "https",
"CloudFront-Is-Desktop-Viewer": "true",
"CloudFront-Is-Mobile-Viewer": "false",
"CloudFront-Is-SmartTV-Viewer": "false",
"CloudFront-Is-Tablet-Viewer": "false",
"CloudFront-Viewer-Country": "US",
"Host": "1234567890.execute-api.{dns_suffix}",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Custom User Agent String",
"Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)",
"X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==",
"X-Forwarded-For": "127.0.0.1, 127.0.0.2",
"X-Forwarded-Port": "443",
"X-Forwarded-Proto": "https"
},
"requestContext": {
"accountId": "123456789012",
"resourceId": "123456",
"stage": "prod",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
"identity": {
"cognitoIdentityPoolId": null,
"accountId": null,
"cognitoIdentityId": null,
"caller": null,
"apiKey": null,
"sourceIp": "127.0.0.1",
"cognitoAuthenticationType": null,
"cognitoAuthenticationProvider": null,
"userArn": null,
"userAgent": "Custom User Agent String",
"user": null
},
"resourcePath": "/{proxy+}",
"httpMethod": "POST",
"apiId": "1234567890"
}
}
解决方案
推荐阅读
- sharepoint - 如何计算工作流 2013 中的项目数
- javascript - 如何使用 Javascript 将数组拆分为基于值的多个数组?
- authentication - 使用 ASP.Net Core 检测外部 Azure AD 用户
- sql - 向上舍入 5 美分
- javascript - 重定向回应用程序的缓存版本 (IE 11 - DOM7011) - ReactJS
- typescript - 基于输入参数类型的打字稿类型
- html - 单击填充时模态引导关闭模态
- neural-network - 在 RaspberryPi 上构建语音到文本神经网络
- javascript - 将 React withRouter 用于类组件
- excel - EXCEL:求解器约束