Exemple #1
0
        public static String ConcatQueryString(Dictionary <String, String> parameters)
        {
            if (null == parameters)
            {
                return(null);
            }
            StringBuilder sb = new StringBuilder();

            foreach (var entry in parameters)
            {
                String key = entry.Key;
                String val = entry.Value;

                sb.Append(AcsURLEncoder.Encode(key));
                if (val != null)
                {
                    sb.Append("=").Append(AcsURLEncoder.Encode(val));
                }
                sb.Append("&");
            }

            int strIndex = sb.Length;

            if (parameters.Count > 0)
            {
                sb.Remove(strIndex - 1, 1);
            }

            return(sb.ToString());
        }
        public string ComposeStringToSign(MethodType?method, string uriPattern, ISigner signer,
                                          Dictionary <string, string> queries, Dictionary <string, string> headers, Dictionary <string, string> paths)
        {
            var sortedDictionary = SortDictionary(queries);

            StringBuilder canonicalizedQueryString = new StringBuilder();

            foreach (var p in sortedDictionary)
            {
                canonicalizedQueryString.Append("&")
                .Append(AcsURLEncoder.PercentEncode(p.Key)).Append("=")
                .Append(AcsURLEncoder.PercentEncode(p.Value));
            }

            StringBuilder stringToSign = new StringBuilder();

            stringToSign.Append(method.ToString());
            stringToSign.Append(SEPARATOR);
            stringToSign.Append(AcsURLEncoder.PercentEncode("/"));
            stringToSign.Append(SEPARATOR);
            stringToSign.Append(AcsURLEncoder.PercentEncode(
                                    canonicalizedQueryString.ToString().Substring(1)));

            return(stringToSign.ToString());
        }