本文整理汇总了C#中System.Collections.Specialized.NameValueCollection.AddParameter方法的典型用法代码示例。如果您正苦于以下问题:C# NameValueCollection.AddParameter方法的具体用法?C# NameValueCollection.AddParameter怎么用?C# NameValueCollection.AddParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Specialized.NameValueCollection
的用法示例。
在下文中一共展示了NameValueCollection.AddParameter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseOAuthAuthorizationHeader
/// <summary>
/// Parse the OAuth AuthenticationHeaderValue.Parameter into a NameValueCollection.
/// </summary>
/// <param name="authorizationHeader">The AuthorizationHeaderValue to parse.</param>
/// <returns>A NameValueCollection of all the parameters found.</returns>
public static NameValueCollection ParseOAuthAuthorizationHeader(this AuthenticationHeaderValue authorizationHeader)
{
if (!authorizationHeader.Scheme.Equals(OAuthConstants.AuthScheme))
{
throw new LtiException("Invalid Authorization scheme");
}
var parameters = new NameValueCollection();
foreach (var pair in authorizationHeader.Parameter.Split(','))
{
var keyValue = pair.Split('=');
var key = keyValue[0].Trim();
// Ignore unknown parameters
if (!OAuthConstants.OAuthParameters.Any(p => p.Equals(key)))
continue;
var value = WebUtility.UrlDecode(keyValue[1].Trim('"'));
parameters.AddParameter(key, value);
}
return parameters;
}
示例2: CreateLtiOutcomesRequest
private static HttpWebRequest CreateLtiOutcomesRequest(imsx_POXEnvelopeType imsxEnvelope, string url, string consumerKey, string consumerSecret)
{
var webRequest = (HttpWebRequest) WebRequest.Create(url);
webRequest.Method = "POST";
webRequest.ContentType = "application/xml";
var parameters = new NameValueCollection();
parameters.AddParameter(OAuthConstants.ConsumerKeyParameter, consumerKey);
parameters.AddParameter(OAuthConstants.NonceParameter, Guid.NewGuid().ToString());
parameters.AddParameter(OAuthConstants.SignatureMethodParameter, OAuthConstants.SignatureMethodHmacSha1);
parameters.AddParameter(OAuthConstants.VersionParameter, OAuthConstants.Version10);
// Calculate the timestamp
var ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
var timestamp = Convert.ToInt64(ts.TotalSeconds);
parameters.AddParameter(OAuthConstants.TimestampParameter, timestamp);
// Calculate the body hash
using (var ms = new MemoryStream())
using (var sha1 = new SHA1CryptoServiceProvider())
{
ImsxRequestSerializer.Serialize(ms, imsxEnvelope);
ms.Position = 0;
ms.CopyTo(webRequest.GetRequestStream());
var hash = sha1.ComputeHash(ms.ToArray());
var hash64 = Convert.ToBase64String(hash);
parameters.AddParameter(OAuthConstants.BodyHashParameter, hash64);
}
// Calculate the signature
var signature = OAuthUtility.GenerateSignature(webRequest.Method, webRequest.RequestUri, parameters,
consumerSecret);
parameters.AddParameter(OAuthConstants.SignatureParameter, signature);
// Build the Authorization header
var authorization = new StringBuilder(OAuthConstants.AuthScheme).Append(" ");
foreach (var key in parameters.AllKeys)
{
authorization.AppendFormat("{0}=\"{1}\",", key, WebUtility.UrlEncode(parameters[key]));
}
webRequest.Headers["Authorization"] = authorization.ToString(0, authorization.Length - 1);
return webRequest;
}