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


C# HttpWebResponse.ReadAllAndClose方法代码示例

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


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

示例1: GetResponse

		public override WebResponse GetResponse()
		{
			lock(this)
			{
				if (_isAborted)
					throw new WebException ("The operation has been aborted.", WebExceptionStatus.RequestCanceled);
				if(!_isConnectionOpened)
					OpenConnection();
				if(_response == null)
				{
					try
					{	
						synchHeaders();
						InternalExecuteMethod ();						
						int numOfRedirects = 0;
						while (isRedirectNeeded (_method) && _allowAutoRedirect && numOfRedirects < MaxAutoRedirections) {
							if (!HandleManualyRedirect ())
								break;
							numOfRedirects++;
						}
						
						//todo right place to re-put all headers again...
						mainsoft.apache.commons.httpclient.Header hostHeader =
							_method.getRequestHeader("Host");
						if(hostHeader != null)
							Headers.SetInternal("Host", hostHeader.getValue());

						_response = new HttpWebResponse(_method, _state, _stateCache, GetAddress(), this.MethodName);
						
						if(_response != null && 
							_response.Cookies != null && 
							_response.Cookies.Count > 0)
						{
							if(CookieContainer != null)
							{
								foreach(Cookie cooky in _response.Cookies)
								{
									CookieContainer.Add(GetAddress(), cooky);
								}
							}
						}

						_hasResponse = true;
						int respCodeAsInt = (int) _response.StatusCode;
						if(respCodeAsInt >= 400)
						{
							// The WebException contains the readable (not closed) response stream.
							// So, in case of WebException, we should read all data from the 
							// network response stream into the memory stream, and after that
							// close the underlying network stream. The following requests to read
							// from the stream will actually read from the memory stream.
							// So, the this.Abort() should not be called in this case.
							_response.ReadAllAndClose();
							//this.Abort();
							throw new WebException("The remote server returned an error: (" + respCodeAsInt +") " +_response.StatusCode, null, WebExceptionStatus.ProtocolError, _response);
						}
						Header location = _method.getResponseHeader ("location");
						if (isRedirectNeeded (_method) && location == null && _method.getFollowRedirects ())
						{
							// See comments above for the error >= 400
							_response.ReadAllAndClose();
							//this.Abort();
							throw new WebException("Got response code "+_response.StatusCode+", but no location provided", null, WebExceptionStatus.ProtocolError, _response);
						}
					}
					catch(ProtocolException e)
					{
						throw new WebException("", e);
					}
					catch(java.net.ConnectException e)
					{
						throw new WebException("Unable to connect to the remote server.", e);
					}
					catch(java.net.SocketTimeoutException e)
					{
						throw new WebException("Timeout exceeded", e);
					}
					catch(java.io.IOException e)
					{
						throw new WebException("", e);
					}
				}
				return _response;
			}

		}
开发者ID:whereisaaron,项目名称:mono,代码行数:86,代码来源:VMWHttpProvider.jvm.cs


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