本文整理汇总了C#中System.Collections.Specialized.NameValueCollection.ToNormalizedString方法的典型用法代码示例。如果您正苦于以下问题:C# NameValueCollection.ToNormalizedString方法的具体用法?C# NameValueCollection.ToNormalizedString怎么用?C# NameValueCollection.ToNormalizedString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Specialized.NameValueCollection
的用法示例。
在下文中一共展示了NameValueCollection.ToNormalizedString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateSignatureBase
/// <summary>
/// Generate the signature base that is used to produce the signature
/// </summary>
/// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
/// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
/// <param name="parameters"></param>
/// <returns>The signature base</returns>
internal static string GenerateSignatureBase(string httpMethod, Uri url, NameValueCollection parameters)
{
// https://tools.ietf.org/html/rfc5849#section-3.4.1.1
var signatureBase = new StringBuilder();
signatureBase.Append(httpMethod.ToRfc3986EncodedString().ToUpperInvariant()).Append('&');
// https://tools.ietf.org/html/rfc5849#section-3.4.1.2
// Exclude the query (query parameters in parameters collection) from the URI
var normalizedUrl = $"{url.Scheme.ToLowerInvariant()}://{url.Host.ToLowerInvariant()}";
if (!((url.Scheme == "http" && url.Port == 80) || (url.Scheme == "https" && url.Port == 443)))
{
normalizedUrl += ":" + url.Port;
}
normalizedUrl += url.AbsolutePath;
signatureBase.Append(normalizedUrl.ToRfc3986EncodedString()).Append('&');
// Construct the signature string
signatureBase.Append(parameters.ToNormalizedString().ToRfc3986EncodedString());
return signatureBase.ToString();
}
示例2: GenerateSignatureBase
/// <summary>
/// Generate the signature base that is used to produce the signature
/// </summary>
/// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
/// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
/// <param name="parameters"></param>
/// <returns>The signature base</returns>
public static string GenerateSignatureBase(string httpMethod, Uri url, NameValueCollection parameters)
{
// RFC 5849 3.4.1.1
var signatureBase = new StringBuilder();
signatureBase.Append(httpMethod.ToRfc3986EncodedString().ToUpperInvariant()).Append('&');
// RFC 5849 3.4.1.2
var normalizedUrl = string.Format("{0}://{1}", url.Scheme.ToLowerInvariant(), url.Host.ToLowerInvariant());
if (!((url.Scheme == "http" && url.Port == 80) || (url.Scheme == "https" && url.Port == 443)))
{
normalizedUrl += ":" + url.Port;
}
normalizedUrl += url.AbsolutePath;
signatureBase.Append(normalizedUrl.ToRfc3986EncodedString()).Append('&');
// Per RFC 5849 3.4.1.3, do not include the OAuth signature or realm in the signature base string
var excludedNames = new List<string> {OAuthConstants.SignatureParameter, OAuthConstants.RealmParameter};
// Construct the signature string
signatureBase.Append(parameters.ToNormalizedString(excludedNames).ToRfc3986EncodedString());
return signatureBase.ToString();
}