doudouchan5830 2018-10-12 14:06
浏览 51

如何使用AWS PHP SDK访问API网关端点

I need to POST data to an AWS API Gateway URL.

I have no clue how to do this with PHP. (Like I cannot imagine it to be this difficult.)

Any help would be appreciated.

I need to send a JSON body to an API Gateway API (IAM) the SDK does not seem to have any documentation that can help me.

I need to POST this:

{
    "entity": "Business",
    "action": "read",
    "limit": 100
}

To an API gateway endpoint using sig 4 Example endpoint (https://myendpoint.com/api)

  • 写回答

1条回答 默认 最新

  • douhui2307 2018-10-12 14:29
    关注

    You can install AWS php sdk via composer composer require aws/aws-sdk-php and here is the github https://github.com/aws/aws-sdk-php . In case you want to do something simple or they don't have what you are looking for you can use curl in php to post data.

    $ch = curl_init();
    
    $data = http_build_query([
        "entity" => "Business",
        "action" => "read",
        "limit" => 100
    ]);
    
    curl_setopt_array($ch, [
        CURLOPT_URL => "https://myendpoint.com/api",
        CURLOPT_FOLLOWLOCATION => true
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => $data
    ]);
    
    $response = curl_exec($ch);
    $error = curl_error($ch);
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制