generateCanonicalRequest method

String generateCanonicalRequest(
  1. Map<String, String> headers,
  2. String payload
)

按如下伪代码格式拼接规范请求串(CanonicalRequest):

CanonicalRequest =
  HTTPRequestMethod + '\n' +
  CanonicalURI + '\n' +
  CanonicalQueryString + '\n' +
  CanonicalHeaders + '\n' +
  SignedHeaders + '\n' +
  HashedRequestPayload

Ref https://cloud.tencent.com/document/api/382/52072#1.-.E6.8B.BC.E6.8E.A5.E8.A7.84.E8.8C.83.E8.AF.B7.E6.B1.82.E4.B8.B2

根据以上规则,示例中得到的规范请求串如下:

POST
/

content-type:application/json; charset=utf-8
host:cvm.tencentcloudapi.com
x-tc-action:describeinstances

content-type;host;x-tc-action
35e9c5b0e3ae67532d3c9f17ead6c90222632e5b1ff7f6e89887f1398934f064

Implementation

String generateCanonicalRequest(Map<String, String> headers, String payload) {
  final httpRequestMethod = _method.toUpperCase();
  final canonicalUri = _endpoint.path;
  final canonicalQueryString = ''; // Is empty for Tencent Cloud SMS.
  final canonicalHeaders = generateCanonicalHeaders(headers);
  final signedHeaders = generateSignedHeaders(headers);
  final hashedRequestPayload = generateHashedRequestPayload(payload);

  return [
    httpRequestMethod,
    canonicalUri,
    canonicalQueryString,
    canonicalHeaders,
    signedHeaders,
    hashedRequestPayload,
  ].join('\n');
}