Todos os produtos
Search
Central de documentação

API Gateway:Exemplos de chamada de API

Última atualização: Aug 26, 2026

O API Gateway permite chamar serviços de API de outros usuários da Alibaba Cloud ou de provedores de serviços terceirizados. O API Gateway também oferece diversos serviços de gerenciamento e suporte.

Chamar uma API

Use os SDKs multilíngues disponíveis no console do API Gateway para chamar uma API (Download SDKs and documents). Alternativamente, escreva suas próprias requisições HTTP ou HTTPS para fazer a chamada.

As seções a seguir descrevem as chamadas de API e fornecem exemplos:

  1. Requisição

    Uma URL de requisição é composta por um nome de domínio e um caminho.

    Use o nome de domínio vinculado ao grupo de APIs. Caso nenhum domínio esteja vinculado ao grupo, use o nome de domínio de segundo nível do grupo.

    http://e710888d3ccb4638a723ff8d03837095-cn-qingdao.aliapi.com/demo/post

    Método da requisição:

    POST

    Corpo da requisição:

    FormParam1=FormParamValue1&FormParam2=FormParamValue2   # HTTP Request Body

    Cabeçalho da requisição:

    Host: e710888d3ccb4638a723ff8d03837095-cn-qingdao.aliapi.com
    Date: Mon, 22 Aug 2016 11:21:04 GMT
    User-Agent: Apache-HttpClient/4.1.2 (java 1.6)
    Content-Type: application/x-www-form-urlencoded; charset=UTF-8 
    # The type of the request body. Set this based on the actual content of the request body.
    
    Accept: application/json 
    # The type of the response body. Some APIs return data in a specific format based on the specified response type. Manually specify this request header. If this header is not specified, some HTTP clients use the default value */*, which may cause a signature error.
    
    X-Ca-Request-Mode: debug 
    # Specifies whether to enable debug mode. This parameter is not case-sensitive. If this parameter is not specified, debug mode is disabled by default. Enable this mode during the API debugging phase.
    
    X-Ca-Version: 1  
    # The version number of the API. All APIs support only version 1. You can leave this request header unspecified. The default version number is 1.
    
    X-Ca-Signature-Headers: X-Ca-Request-Mode,X-Ca-Version,X-Ca-Stage,X-Ca-Key,X-Ca-Timestamp 
    # The custom request headers that are included in the signature calculation. The server reads the request headers based on this configuration to sign the request. This configuration does not include the Content-Type, Accept, Content-MD5, and Date request headers. These headers are already included in the basic signature structure. For more information, see the request signature documentation.
    
    X-Ca-Stage: RELEASE  
    # The stage of the API. Valid values: TEST, PRE, and RELEASE. This parameter is not case-sensitive. The API provider can select the stage to which the API is published. The API can be called only after it is published to the specified stage. Otherwise, the system reports that the API is not found or the URL is invalid.
    
    X-Ca-Key: 60022326  
    # The AppKey of the request. Generate the AppKey in the API Gateway console. An API can be called only after it is authorized. By default, APIs purchased from channels such as Alibaba Cloud Marketplace are already authorized for the app. All Alibaba Cloud products share one AppKey system. Delete an AppKey with caution to avoid affecting other activated Alibaba Cloud products.
    
    X-Ca-Timestamp: 1471864864235 
    # The timestamp of the request. This value is the number of milliseconds that have elapsed since 00:00:00 UTC on January 1, 1970. The timestamp is valid for 15 minutes.
    
    X-Ca-Nonce:b931bc77-645a-4299-b24b-f3669be577ac  
    # The unique ID of the request. The combination of AppKey, API, and Nonce must be unique within 15 minutes. This parameter is used with the timestamp to prevent replay attacks.
    
    X-Ca-Signature: FJleSrCYPGCU7dMlLTG+UD3Bc5Elh3TV3CWHtSKh1Ys= 
    # The request signature.
    
    CustomHeader: CustomHeaderValue  
    # A custom request header. This is only an example. In an actual request, you can set multiple custom request headers based on the API definition.
  2. Resposta

    Código de status:

    400  
    # The status code of the response. A value from 200 to 299 indicates success. A value from 400 to 499 indicates a client error. A value of 500 or greater indicates a server error.

    Cabeçalho da resposta:

    X-Ca-Request-Id: 7AD052CB-EE8B-4DFD-BBAF-EFB340E0A5AF 
    # The unique ID of the request. After a request enters API Gateway, API Gateway generates a request ID and returns it to the client in the response header. Record this request ID on both the client and the backend service for troubleshooting and tracking.
    
    X-Ca-Error-Message: Invalid Url  
    # The error message returned by API Gateway. If an error occurs in a request, API Gateway returns the error message to the client in a response header.
    
    X-Ca-Debug-Info: {"ServiceLatency":0,"TotalLatency":2}  
    # If debug mode is enabled, debug information is returned. This information may change and is for reference only during the joint debugging phase.
                            
  • Toda requisição de API deve incluir informações de assinatura, independentemente do uso de HTTP ou HTTPS. O AppKey identifica o solicitante, enquanto o AppSecret funciona como chave para criptografar a string de assinatura e validá-la no servidor. Para mais detalhes sobre o cálculo e o envio da assinatura criptografada, consulte Use digest authentication to call an API.

  • Para obter códigos de exemplo sobre o cálculo de assinaturas, acesse os exemplos de SDK na página Download SDKs no console do API Gateway.

  • Para mais informações, consulte Overview.