示例#1
0
        private byte[] PostProcessPostParameters(WebRequest request, Uri uri)
        {
            var body = "";
            switch (ParameterHandling)
            {
                case OAuthParameterHandling.HttpAuthorizationHeader:
                    SetAuthorizationHeader(request, "Authorization");                    
#if SILVERLIGHT
                    var postParameters = new WebParameterCollection(uri.Query.ParseQueryString());
#else
                    var postParameters = new WebParameterCollection(uri.Query.ParseQueryString());
#endif
                    // Only use the POST parameters that exist in the body
                    postParameters = new WebParameterCollection(postParameters.Where(p => !p.Name.StartsWith("oauth_")));

                    // Append any leftover values to the POST body
                    var nonAuthParameters = GetPostParametersValue(postParameters, true /* escapeParameters */);
                    if (body.IsNullOrBlank())
                    {
                        body = nonAuthParameters;
                    }
                    else
                    {
                        if (!nonAuthParameters.IsNullOrBlank())
                        {
                            body += "&".Then(nonAuthParameters);
                        }
                    }
                    break;
                case OAuthParameterHandling.UrlOrPostParameters:
                    body = GetPostParametersValue(Parameters, false /* escapeParameters */);
                    break;
            }

            var content = Encoding.UTF8.GetBytes(body);
            return content;
        }
示例#2
0
        /// <summary>
        /// Sorts a <see cref="WebParameterCollection"/> by name, and then value if equal.
        /// </summary>
        /// <param name="parameters">A collection of parameters to sort</param>
        /// <returns>A sorted parameter collection</returns>
        public static WebParameterCollection SortParametersExcludingSignature(WebParameterCollection parameters)
        {
            var copy = new WebParameterCollection(parameters);
            var exclusions = copy.Where(n => n.Name.EqualsIgnoreCase("oauth_signature"));

            copy.RemoveAll(exclusions);
            copy.ForEach(p => p.Value = UrlEncodeStrict(p.Value));
            copy.Sort((x, y) => x.Name.Equals(y.Name) ? x.Value.CompareTo(y.Value) : x.Name.CompareTo(y.Name));
            return copy;
        }