Search the docs or ask a question...

Overview

Update time: 2021/11/08 08:59:10

Request structure

The URL that initiates an API request is concatenated with different parameters by using a fixed request structure. The request structure of server APIs for Live Streaming consists of the following components:

  • URL: the address used for specific business requests. For more information, see each API document.
  • Header: contains authentication information such as CommsEase AppKey and CheckSum.
  • Body: contains request parameters for specified APIs. If an API has no request parameters, the request body does not take any parameters.

Each API document provides a sample request for reference. You can complete the sample request before making a request. If the API call is successful, the response parameters will be displayed. If the call fails, an error may occur. You can analyze and troubleshoot the error code.

The header includes relevant parameters for authentication. If not necessary, these parameters are no longer described in the separate API document. Each request must take these parameters before the request can be initiated.

Common request parameters

For security reasons, the validity period of each CheckSum is within 5 minutes after CurTime. We recommend that you generate a new CheckSum for each request, and make sure that the server that initiated the request is synchronized with the standard time, such as the NTP service.

Parameter Type Description
AppKey String The CommsEase console displays the AppKey of a specified application.
Nonce String A random number. The number must be 1 to 128 characters in length.
CurTime String The current Unix timestamp, which is the number of seconds from January 1, 1970, at 0:00:0 to the present time. The CurTime field in the request header must take in the valid Unix timestamp. Before you call a server API, make sure that the caller's local server time is correct. Otherwise, an error response with the 414 status code is returned due to the invalid value of the CurTime field.
CheckSum String The value of CheckSum is in String format and contains lowercase letters. The calculation method: Hash the string concatenated with AppSecret, Nonce, and CurTime using the SHA-1 algorithm, and convert the result into hexadecimal characters. CheckSum = sha1(AppSecret + Nonce + CurTime).

API authentication

API calls are authenticated using the common parameters in the request header.

All the APIs described in this topic are available on the server side. Developers must manage AppSecret used to calculate CheckSum. AppSecret can be stored and used on the server side of the application other than on the client or embedded in the code of frontend applications, such as web pages.

Example for calculating CheckSum using JAVA:

JAVAimport java.security.MessageDigest;
public class CheckSumBuilder {
    public static String getCheckSum(String appSecret, String nonce, String curTime) {
        return encode("sha1", appSecret + nonce + curTime);
    }
    private static String encode(String algorithm, String value) {
        if (value == null) {
            return null;
        }
        try {
            MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
            messageDigest.update(value.getBytes());
            return getFormattedText(messageDigest.digest());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    private static String getFormattedText(byte[] bytes) {
        int len = bytes.length;
        StringBuilder buf = new StringBuilder(len * 2);
        for (int j = 0; j < len; j++) {
            buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
            buf.append(HEX_DIGITS[bytes[j] & 0x0f]);
        }
        return buf.toString();
    }
    private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
}

Body

Content-Type of a server API request is application/json. The body data must be in JSON format.

Service URL

The domain name used by CommsEase to deliver live streaming service: vcloud.163.com.

Communication protocol

All APIs that belong to CommsEase Live Streaming are called over HTTPS, which provides a high-security communication channel.

Request method

All APIs use only the POST method.

Character encoding

UTF-8 encoding is used.

Response structure

The data returned by all responses are in JSON format. The returned fields are described in the following table:

Parameter Type Description
code int The response status code.
ret String Business-related returns.
msg String When the response status code is a value other than 200, the parameter displays an error message.
requestId String The unique request identifier.
Was this page helpful?
Yes
No
  • Request structure
  • Header
  • Common request parameters
  • API authentication
  • Body
  • Service URL
  • Communication protocol
  • Request method
  • Character encoding
  • Response structure