private string ComposeStringToSign(MethodType?method, Dictionary <string, string> queries) { //排序 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)); } var t = canonicalizedQueryString.ToString().Substring(1); 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()); }
/// <summary> /// 构造键值参数字符串UTF-8 /// </summary> /// <param name="parameters"></param> /// <returns></returns> private 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()); }