2017-10-10 8 views
0

API Gatway Post vars(イベント['body'] ['param'])がC#Lambda Funcionに渡される方法を理解していますか?C#AWS API Gatway Post Params

私が持っている:

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

しかし、郵便配達(ポストキー値: "こんにちは:世界")を使用して、それが返されます。

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

(それが表すようになっているものも考えて)

私が行う場合:

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

I「要請本体:」

空のボディですか?

投稿値はどこですか?

これは、フォーム・データを使用しており、ボディマッピングがある:いいえ、まだ体のために私にGiberishを与える

"## 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" 
    } 
} 

答えて

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

: "ボディ\" \:\を "\\\" LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTY2OTI2MzM4NDA3NzA5NDM1NzMzOTQ5Mg0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJIZWxsb3dvcmxkIg0KDQpXaGF0DQotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tNjY5MjYzMzg0MDc3MDk0MzU3MzM5NDkyLS0NCg = = –

+0

コンテンツタイプ - application/jsonを使用しましたか? –

+0

いいえ、わかりませんでしたが、バイナリ情報(画像)を送信する必要があるため、mulitpart/form-dataをコンテンツタイプとして使用しています。私は、このレッスンに基づいてmultipart/form-dataを使用するためのバイナリサポートをセットアップしました。[link](https://aws.amazon.com/blogs/compute/binary-support-for-api-integrations- with-amazon-api-gateway /) –

関連する問題