Exemplo n.º 1
0
        /// <summary>
        /// $HttpString = [HttpMethod]\n[HttpURI]\n[HttpParameters]\n[HttpHeaders]\n
        /// </summary>
        /// <param name="method"></param>
        /// <param name="path"></param>
        /// <param name="queryParameters"></param>
        /// <param name="headers"></param>
        /// <returns></returns>
        public string GenerateSource(string method, string path, Dictionary <string, string> queryParameters, Dictionary <string, string> headers)
        {
            StringBuilder formatString = new StringBuilder();

            formatString.Append(method.ToLower()).Append('\n'); // method
            formatString.Append(path).Append('\n');             // path

            //check header and parameter in request
            string headerResult    = CheckHeaders(headers);
            string parameterResult = CheckParameters(queryParameters);

            if (parameterResult != null)
            {
                formatString.Append(parameterResult);                          // parameters
            }
            formatString.Append('\n');
            if (headerResult != null)
            {
                formatString.Append(headerResult);                       // headers
            }
            formatString.Append('\n');
            StringBuilder stringToSign = new StringBuilder();

            stringToSign.Append(CosAuthConstants.SHA1).Append('\n');
            stringToSign.Append(signTime).Append('\n');
            stringToSign.Append(DigestUtils.GetSha1ToHexString(formatString.ToString(), Encoding.UTF8)).Append('\n');
            return(stringToSign.ToString());
        }