
# curl
#### 操作场景
使用curl命令调用APP认证的API时，您需要先下载JavaScript SDK生成curl命令，然后将curl命令复制到命令行调用API。
#### 前提条件
已获取API的调用信息，具体参见[认证前准备](https://support.huaweicloud.com/devg-apig/apig-dev-180907066.html)。
#### 调用API示例
1. 使用JavaScript SDK生成curl命令。 
   请在API网关控制台选择"帮助中心"，在"SDK使用指引"页签中下载对应语言所使用SDK。
   或直接下载[JavaScript SDK](https://obs.cn-north-1.myhuaweicloud.com/apig-sdk/ApiGateway-javascript-sdk.zip)的最新版本，并解压。在浏览器中打开demo.html，页面如下图所示。
   ![](https://support.huaweicloud.com/devg-apig/zh-cn_image_0000002225165249.png "点击放大")
   
   
2. 填入Key、Secret、方法名、请求协议、域名和url。 
   ```
   // 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****100c
   Secret=******
   Method=POST
   Url=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命令。
   
   
 
