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


C# NameValueCollection.FilterHeaders方法代码示例

本文整理汇总了C#中NameValueCollection.FilterHeaders方法的典型用法代码示例。如果您正苦于以下问题:C# NameValueCollection.FilterHeaders方法的具体用法?C# NameValueCollection.FilterHeaders怎么用?C# NameValueCollection.FilterHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NameValueCollection的用法示例。


在下文中一共展示了NameValueCollection.FilterHeaders方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Map

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="request"></param>
        /// <param name="result"></param>
        /// <param name="statusCode"></param>
        /// <param name="exception"></param>
        /// <returns></returns>
        public Attachment Map(string key, HttpWebRequest request, IAsyncResult result, out HttpStatusCode statusCode,
                              out Exception exception)
        {
            try
            {
                var response = request.EndGetResponse(result) as HttpWebResponse;
                Stream stream = response.GetResponseStream();

                statusCode = response.StatusCode;
                exception = null;

                var headers = new NameValueCollection();
                foreach (string headerKey in response.Headers.AllKeys)
                {
                    headers.Add(headerKey, response.Headers[key]);
                }

                return new Attachment
                           {
                               Data = stream.ReadData(),
                               Etag = new Guid(response.Headers["ETag"]),
                               Metadata = headers.FilterHeaders(isServerDocument: false)
                           };
            }
            catch (WebException ex)
            {
                var httpWebResponse = ex.Response as HttpWebResponse;
                if (httpWebResponse == null)
                {
                    throw;
                }

                statusCode = httpWebResponse.StatusCode;
                exception = AsyncServerClient.ExtractException(httpWebResponse);

                if (httpWebResponse.StatusCode == HttpStatusCode.Conflict)
                {
                    JObject conflictsDoc = JObject.Load(new BsonReader(httpWebResponse.GetResponseStream()));
                    string[] conflictIds =
                        conflictsDoc.Value<JArray>("Conflicts").Select(x => x.Value<string>()).ToArray();

                    throw new ConflictException("Conflict detected on " + key +
                                                ", conflict must be resolved before the attachment will be accessible")
                              {
                                  ConflictedVersionIds = conflictIds
                              };
                }

                if (httpWebResponse.StatusCode == HttpStatusCode.NotFound)
                {
                    return null;
                }

                throw;
            }
        }
开发者ID:aduggleby,项目名称:ravendb,代码行数:65,代码来源:AttachmentMapper.cs


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