当前位置: 首页>>代码示例>>C#>>正文


C# NameValueCollection.AddParameter方法代码示例

本文整理汇总了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;
        }
开发者ID:easygenerator,项目名称:LtiLibrary,代码行数:27,代码来源:AuthorizationHeaderValueExtensions.cs

示例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;
        }
开发者ID:easygenerator,项目名称:LtiLibrary,代码行数:45,代码来源:OutcomesClient.cs


注:本文中的System.Collections.Specialized.NameValueCollection.AddParameter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。