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


C# HttpWebResponse.Dispose方法代码示例

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


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

示例1: ReadPage

        private string ReadPage(HttpWebResponse response)
        {
            string html = String.Empty;

            try
            {
                using (Stream inputStream = response.GetResponseStream())
                using (StreamReader reader = new StreamReader(inputStream))
                {
                    html = reader.ReadToEnd();
                }
                response.Dispose();
            }
            catch(NullReferenceException ex)
            {
                Console.WriteLine(ex.Message);
            }

            return html;
        }
开发者ID:ahihudi,项目名称:Weaver,代码行数:20,代码来源:NetworkConnection.cs

示例2: DAVRequestResult

        /// <summary>
        /// Parses the DAV result.
        /// Note that it will only parse if the server status was 207.
        /// There maybe error outputs on 4xx and 5xx but this will not parsed
        /// by this class.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        /// <param name="uri"></param>
        public DAVRequestResult(WebDAV request, HttpWebResponse response, Uri uri)
        {
            Request = request;
            Items = new List<Item>();
            Status = (ServerStatus)Enum.Parse(typeof(ServerStatus), response.StatusCode.ToString(), false);
            StatusText = response.StatusDescription;
            IsMultiState = Status == ServerStatus.MultiStatus;
            _stream = new MemoryStream();
            response.GetResponseStream().CopyTo(_stream);

            // dispose
            response.Dispose();

            _stream.Seek(0, SeekOrigin.Begin);
            if (_stream.Length == 0) return;

            // A kingdom for normal DOMDocument support.
            // Why not XDocument? XmlReader is faster and less resource hungry.
            // A huge multitstatus would be first loaded to memory completely.
            //
            // This reader can only go forward. Read-* methods will cause
            // to jump over elements. Hence we stop at the element and
            // store the element name. Then wait for Text-Elements value
            // to capture.
            using(XmlReader reader = XmlReader.Create(_stream, null)) {

                Item item = new Item();
                var waitForResourceType = false;
                var lastElementName = "";
                var waitForLockScope = false;
                var waitForLockType = false;
                List<DAVLocking> lockingList = null;
                List<PropertyState> propertyStateList = null;
                PropertyState pItem = null;
                DAVLocking litem = null;

                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        // look for special elements
                        case XmlNodeType.Element:
                            if (reader.NamespaceURI == XmlNamespaces.NsDav)
                            {
                                switch (reader.LocalName)
                                {
                                    // DAV Elements

                                    // Response
                                    case Elements.Response:
                                        // start a new item
                                        // pItem must be set before d:prop in order to
                                        // catch non-real properties such "href"
                                        item = new Item();
                                        propertyStateList = new List<PropertyState>();
                                        pItem = new PropertyState();
                                        break;

                                    // Resource type
                                    case Elements.Collection:
                                        if (waitForResourceType)
                                        {
                                            item.ResourceType = ResourceType.Collection;
                                        }
                                        break;

                                    // Lock
                                    case Elements.LockEntry:
                                        litem = new DAVLocking();
                                        lockingList.Add(litem);
                                        break;
                                    case Elements.LockScope:
                                        waitForLockScope = true;
                                        break;
                                    case Elements.LockType:
                                        waitForLockType = true;
                                        break;
                                    case Elements.ExclusiveLocking:
                                        if (waitForLockScope)
                                        {
                                            litem.Scope = DAVLocking.LockScope.Exclusive;
                                        }
                                        break;
                                    case Elements.SharedLocking:
                                        if (waitForLockScope)
                                        {
                                            litem.Scope = DAVLocking.LockScope.Shared;
                                        }
                                        break;
                                    case Elements.WriteLocking:
                                        if (waitForLockType)
//.........这里部分代码省略.........
开发者ID:ErikPel,项目名称:windows-phone,代码行数:101,代码来源:RequestResult.cs

示例3: ProcessResponse

        /// <summary>
        /// Processes the content of response received in context of given request.
        /// </summary>
        protected void ProcessResponse(HttpWebRequest request, HttpWebResponse response, HttpDataSourceResponseType responseType, Exception ex)
        {
            // data reception failed or timeouted/cancelled?
            if (response == null)
            {
                string statusDescription = ex != null
                                               ? string.IsNullOrEmpty(ex.Message)
                                                     ? ex.GetType().Name
                                                     : string.Concat(ex.GetType().Name, ": ", ex.Message)
                                               : "Unknown error";
                ProcessFailedResponse(request, HttpStatusCode.ServiceUnavailable, statusDescription);
                return;
            }

            ProcessSuccessfulResponse(request, response, responseType);
#if WINDOWS_STORE
            response.Dispose();
#else
            response.Close();
#endif
        }
开发者ID:phofman,项目名称:codetitans-libs,代码行数:24,代码来源:HttpDataSource.cs

示例4: ConnectExceptionCleanup

 private void ConnectExceptionCleanup(HttpWebResponse response)
 {
     Dispose();
     if (response != null)
     {
         response.Dispose();
     }
 }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:8,代码来源:ClientWebSocket.cs

示例5: ExtractResponseData

        private void ExtractResponseData(HttpResponse response, HttpWebResponse webResponse)
        {
            using (webResponse)
            {
#if FRAMEWORK
                response.ContentEncoding = webResponse.ContentEncoding;
                response.Server = webResponse.Server;
#endif
                response.ContentType = webResponse.ContentType;
                response.ContentLength = webResponse.ContentLength;
                Stream webResponseStream = webResponse.GetResponseStream();

#if WINDOWS_PHONE
                if (String.Equals(webResponse.Headers[HttpRequestHeader.ContentEncoding], "gzip", StringComparison.OrdinalIgnoreCase))
                {
                    var gzStream = new GZipStream(webResponseStream);
                    ProcessResponseStream(gzStream, response);
                }
                else
                {
                    ProcessResponseStream(webResponseStream, response);
                }
#else
                ProcessResponseStream(webResponseStream, response);
#endif
                response.StatusCode = webResponse.StatusCode;
                response.StatusDescription = webResponse.StatusDescription;
                response.ResponseUri = webResponse.ResponseUri;
                response.ResponseStatus = ResponseStatus.Completed;

#if !PocketPC
                if (webResponse.Cookies != null)
                {
                    foreach (Cookie cookie in webResponse.Cookies)
                    {
                        response.Cookies.Add(new HttpCookie
                        {
                            Comment = cookie.Comment,
                            CommentUri = cookie.CommentUri,
                            Discard = cookie.Discard,
                            Domain = cookie.Domain,
                            Expired = cookie.Expired,
                            Expires = cookie.Expires,
                            HttpOnly = cookie.HttpOnly,
                            Name = cookie.Name,
                            Path = cookie.Path,
                            Port = cookie.Port,
                            Secure = cookie.Secure,
                            TimeStamp = cookie.TimeStamp,
                            Value = cookie.Value,
                            Version = cookie.Version
                        });
                    }
                }
#endif
                foreach (var headerName in webResponse.Headers.AllKeys)
                {
                    var headerValue = webResponse.Headers[headerName];
                    response.Headers.Add(new HttpHeader { Name = headerName, Value = headerValue });
                }
#if WINDOWS_UAP
                webResponse.Dispose();
#else
                webResponse.Close();
#endif
            }
        }
开发者ID:st1pps,项目名称:RestSharp,代码行数:67,代码来源:Http.cs


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