generateCanonicalRequest method
按如下伪代码格式拼接规范请求串(CanonicalRequest):
CanonicalRequest =
HTTPRequestMethod + '\n' +
CanonicalURI + '\n' +
CanonicalQueryString + '\n' +
CanonicalHeaders + '\n' +
SignedHeaders + '\n' +
HashedRequestPayload
根据以上规则,示例中得到的规范请求串如下:
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');
}