示例#1
0
        /// <summary>
        /// Constructs the parameters as string
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private string GetParametersAsString(IDictionary <string, string> parameters)
        {
            StringBuilder data = new StringBuilder();

            foreach (string key in (IEnumerable <string>)parameters.Keys)
            {
                string value = parameters[key];
                if (value != null)
                {
                    data.Append(key);
                    data.Append('=');
                    data.Append(MwsUtil.UrlEncode(value, false));
                    data.Append('&');
                }
            }
            string result = data.ToString();

            return(result.Remove(result.Length - 1));
        }
示例#2
0
        /**
         * Calculate String to Sign for SignatureVersion 2
         *
         * @param serviceUri
         *
         * @param parameters
         *            request parameters
         * @return String to Sign
         */
        private static string CalculateStringToSignV2(Uri serviceUri,
                                                      IDictionary <string, string> parameters)
        {
            StringBuilder data = new StringBuilder();

            data.Append("POST");
            data.Append("\n");
            data.Append(serviceUri.Host.ToLower());
            if (!MwsUtil.HasStandardPort(serviceUri))
            {
                data.Append(":");
                data.Append(serviceUri.Port);
            }
            data.Append("\n");
            string uri = serviceUri.LocalPath;

            data.Append(UrlEncode(uri, true));
            data.Append("\n");
            //IDictionary<string, string> sorted = new SortedDictionary<string, string>(parameters, StringComparer.Ordinal);
            IEnumerator <KeyValuePair <string, string> > pairs = parameters.GetEnumerator();
            bool isFirst = true;

            while (pairs.MoveNext())
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    data.Append("&");
                }
                KeyValuePair <string, string> pair = pairs.Current;
                string key = pair.Key;
                data.Append(MwsUtil.UrlEncode(key, false));
                data.Append("=");
                string value = pair.Value;
                data.Append(MwsUtil.UrlEncode(value, false));
            }
            return(data.ToString());
        }