douan3414 2017-07-14 14:10
浏览 263

将数据从aws api网关以x-www-form-urlencoded格式发送到http端点

I have an AWS API gateway proxy method. If I post data to AWS API gateway, then AWS API gateway posts data to my PHP backend. I have this mapping template in API gateway:

{
    "body-json" : $input.json('$'),
    "context" : {
        "cognito-identity-id" : "$context.identity.cognitoIdentityId"
    }
}

The problem is that API gateway posts data in JSON format. And PHP does not understand JSON (content type application/json), $_POST array is empty. PHP understands application/x-www-form-urlencoded format. How to make AWS API gateway to send data in x-www-form-urlencoded format?

  • 写回答

2条回答 默认 最新

  • dongzhuo1930 2017-07-14 14:18
    关注

    Silly question, but have you tried PHP's JSON Decode function?

        $json = '{
           "body-json" : $input.json(\'$\'),
           "context" : {
            "cognito-identity-id" : "$context.identity.cognitoIdentityId"
           }
         }';
    
    $phpArray = json_decode($json, true);
    

    Which will produce an associative PHP array from that json.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器