本文整理汇总了C#中QueryParameters.Sort方法的典型用法代码示例。如果您正苦于以下问题:C# QueryParameters.Sort方法的具体用法?C# QueryParameters.Sort怎么用?C# QueryParameters.Sort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueryParameters
的用法示例。
在下文中一共展示了QueryParameters.Sort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateSignature
/// <summary>
/// Generate Signature
/// </summary>
/// <param name="requestURL"></param>
/// <param name="oauthParameters"></param>
/// <param name="consumerKey"></param>
/// <param name="consumerSecret"></param>
/// <param name="signatureType"></param>
/// <param name="httpMethod"></param>
/// <param name="tokenSecret"></param>
/// <returns></returns>
public string GenerateSignature(Uri requestURL, QueryParameters oauthParameters, string consumerKey, string consumerSecret,
SIGNATURE_TYPE signatureType, TRANSPORT_METHOD httpMethod, string tokenSecret)
{
QueryParameters tmpOauthParameters = new QueryParameters();
foreach (var param in oauthParameters)
{
if (param.Value.ToLower().Contains("http://") || param.Value.ToLower().Contains("https://"))
tmpOauthParameters.Add(new QueryParameter(param.Key, Utility.UrlEncode(param.Value)));
else
tmpOauthParameters.Add(new QueryParameter(param.Key, param.Value));
}
tmpOauthParameters[OAuthSignatureMethodKey] = ParseSignatureEnum(signatureType);
string signature = "";
StringBuilder signatureBase = new StringBuilder();
//1. URL encode and process Request URL
string normalizedRequestUrl;
normalizedRequestUrl = string.Format("{0}://{1}", requestURL.Scheme, requestURL.Host);
if (!((requestURL.Scheme == "http" && requestURL.Port == 80) || (requestURL.Scheme == "https" && requestURL.Port == 443)))
{
normalizedRequestUrl += ":" + requestURL.Port;
}
normalizedRequestUrl += requestURL.AbsolutePath;
normalizedRequestUrl = Utility.UrlEncode(normalizedRequestUrl);
//2. URL Encode callbackUrl (if present)
//if (tmpOauthParameters.HasName(OAuthCallbackKey))
// tmpOauthParameters[OAuthCallbackKey] = Utility.UrlEncode(tmpOauthParameters[OAuthCallbackKey]);
//tmpOauthParameters["scope"] = Utility.UrlEncode(tmpOauthParameters["scope"]);
foreach (var p in Utility.GetQuerystringParameters(requestURL.ToString()))
tmpOauthParameters.Add(p.Key, UrlEncode(HttpUtility.UrlDecode(p.Value)));
//following works for Twitter with spaces
//tmpOauthParameters.Add(p.Key, UrlEncode(HttpUtility.UrlDecode(p.Value)));
//3. Perform Lexographic Sorting
tmpOauthParameters.Sort();
//4. Generate Signature Base
signatureBase.AppendFormat("{0}&", httpMethod.ToString().ToUpper());
signatureBase.AppendFormat("{0}&", normalizedRequestUrl);
signatureBase.AppendFormat("{0}", Utility.UrlEncode(tmpOauthParameters.ToString()));
string sbase = signatureBase.ToString();
logger.Debug("signature base:" + sbase);
//5. Generate Signature
switch (signatureType)
{
case SIGNATURE_TYPE.PLAINTEXT:
{
signature = Utility.UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret));
break;
}
case SIGNATURE_TYPE.HMACSHA1:
{
HMACSHA1 hmacsha1 = new HMACSHA1();
hmacsha1.Key = Encoding.ASCII.GetBytes(string.Format("{0}&{1}", UrlEncode(consumerSecret), string.IsNullOrEmpty(tokenSecret) ? "" : tokenSecret));
signature = GenerateSignatureUsingHash(sbase, hmacsha1);
logger.Debug("HMACSHA1 signature:" + signature);
break;
}
default:
throw new ArgumentException("Unknown signature type", "signatureType");
}
return signature;
}