API网关 APIG-curl:调用API示例

时间:2025-02-12 15:05:07

调用API示例

  1. 使用JavaScript SDK生成curl命令。

    请在API网关控制台选择“帮助中心”,在“SDK使用指引”页签中下载对应语言所使用SDK。

    或直接下载JavaScript SDK的最新版本,并解压。在浏览器中打开demo.html,页面如下图所示。

  2. 填入Key、Secret、方法名、请求协议、 域名 和url。

    123456
    // Directly writing AK/SK in code is risky. For security, encrypt your AK/SK and store them in the configuration file or environment variables.// In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, set environment variables HUAWEICLOUD_SDK_AK and HUAWEICLOUD_SDK_SK.Key=4f5f****100cSecret=******Method=POSTUrl=https://c967a237-cd6c-470e-906f-a8655461897e.apigw.exampleRegion.com

  3. 填入json格式的Query和Headers,填入Body。
  4. 单击“Send request”,生成curl命令。将curl命令复制到命令行,访问API。

    $ curl -X POST "https://c967a237-cd6c-470e-906f-a8655461897e.apigw.exampleRegion.com/" -H "X-Sdk-Date: 20180530T115847Z" -H "Authorization: SDK-HMAC-SHA256 Access=071f***e06a, SignedHeaders=host;x-sdk-date, Signature=9e5314bd156d517******dd3e5765fdde4" -d ""Congratulations, sdk demo is running

    SDK生成的curl命令不符合Window下cmd终端格式时,请在git bash下执行生成的curl命令。

support.huaweicloud.com/devg-apig/apig-dev-180525061.html