本文整理汇总了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;
}
}