C#AWS API Gatway Post Params

时间:2017-10-10 20:24:53

标签: aws-api-gateway

想了解如何获得API Gatway Post vars(事件[' body'] [' param'])传递给我的C#Lambda Funcion?

我有:

public string FunctionHandler(Stream request, ILambdaContext context)
{ StreamReader reader = new StreamReader(request);
 return reader.ReadToEnd();
}

但是,使用postman(Post Key Value:" Hello:world")它会返回:

'\"body-json\" : \"LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTcwMTQxNDY5ODUyNjQwNzI2NDM3ODU2OQ0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJUaGlzS2V5CiINCg0KV2hhdA0KLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTcwMTQxNDY5ODUyNjQwNzI2NDM3ODU2OS0tDQo='

(不知道应该代表什么)

如果我这样做:

public string FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
{   return "request body is:" + request?.Body; }

我得到"请求正文是:"

这是一个空洞的身体?

帖子值在哪里?

这是使用表单数据,正文映射是:

"##  See http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
##  This template will pass through all parameters including path, querystring, header, stage variables, and context through to the integration endpoint via the body/payload
#set($allParams = $input.params())
{
"body-json" : $input.json('$'),
"params" : {
#foreach($type in $allParams.keySet())
    #set($params = $allParams.get($type))
"$type" : {
    #foreach($paramName in $params.keySet())
    "$paramName" : "$util.escapeJavaScript($params.get($paramName))"
        #if($foreach.hasNext),#end
    #end
}
    #if($foreach.hasNext),#end
#end
},
"stage-variables" : {
#foreach($key in $stageVariables.keySet())
"$key" : "$util.escapeJavaScript($stageVariables.get($key))"
    #if($foreach.hasNext),#end
#end
},
"context" : {
    "account-id" : "$context.identity.accountId",
    "api-id" : "$context.apiId",
    "api-key" : "$context.identity.apiKey",
    "authorizer-principal-id" : "$context.authorizer.principalId",
    "caller" : "$context.identity.caller",
    "cognito-authentication-provider" : "$context.identity.cognitoAuthenticationProvider",
    "cognito-authentication-type" : "$context.identity.cognitoAuthenticationType",
    "cognito-identity-id" : "$context.identity.cognitoIdentityId",
    "cognito-identity-pool-id" : "$context.identity.cognitoIdentityPoolId",
    "http-method" : "$context.httpMethod",
    "stage" : "$context.stage",
    "source-ip" : "$context.identity.sourceIp",
    "user" : "$context.identity.user",
    "user-agent" : "$context.identity.userAgent",
    "user-arn" : "$context.identity.userArn",
    "request-id" : "$context.requestId",
    "resource-id" : "$context.resourceId",
    "resource-path" : "$context.resourcePath"
    }
}

2 个答案:

答案 0 :(得分:1)

您返回的字符串是base64编码的格式:

----------------------------669263384077094357339492
Content-Disposition: form-data; name="Helloworld"

What
----------------------------669263384077094357339492--

答案 1 :(得分:0)

{
    "body" : "$util.escapeJavaScript($input.json('$'))"
}