本文整理汇总了C#中System.Net.HttpWebResponse.SetResponseStream方法的典型用法代码示例。如果您正苦于以下问题:C# HttpWebResponse.SetResponseStream方法的具体用法?C# HttpWebResponse.SetResponseStream怎么用?C# HttpWebResponse.SetResponseStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.HttpWebResponse
的用法示例。
在下文中一共展示了HttpWebResponse.SetResponseStream方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetResponse
/// <summary>
/// Returns a response from an Internet resource. Overrides the
/// <itemref>WebRequest</itemref>.<see cref="System.Net.WebRequest.GetResponse"/>
/// method.
/// </summary>
/// <returns>The response from the Internet resource.</returns>
public override WebResponse GetResponse()
{
HttpWebResponse response = null;
try
{
// If response was not sent, Submit the request.
if (!m_requestSent)
{
SubmitRequest();
}
CoreResponseData respData = null;
// reset the total response bytes for the new request.
m_requestStream.m_BytesLeftInResponse = -1;
// create the request timeout timer. This will kill the operation if it takes longer than specified by the Timeout property.
// The underlying socket will be closed to end the web request
using (Timer tmr = new Timer(new TimerCallback(OnRequestTimeout), null, m_timeout, System.Threading.Timeout.Infinite))
{
// Processes response from server. Request stream should already be there.
respData = ParseHTTPResponse(m_requestStream, m_keepAlive);
if (respData.m_statusCode == (int)HttpStatusCode.Continue)
{
if (m_continueDelegate != null)
{
m_continueDelegate(respData.m_statusCode, respData.m_headers);
}
else
{
respData = ParseHTTPResponse(m_requestStream, m_keepAlive);
}
}
}
response = new HttpWebResponse(m_method, m_originalUrl, respData, this);
// Now we look if response has chunked encoding. If it is chunked, we need to set flag in m_requestStream we return.
if (respData.m_chunked)
{
m_requestStream.m_EnableChunkedDecoding = true;
}
// Currently the request and response are the same network streams, but we optimize later.
response.SetResponseStream(m_requestStream);
m_responseStatus = response.StatusCode;
m_responseCreated = true;
}
catch(SocketException se)
{
if (m_requestStream != null)
{
m_requestStream.m_InUse = false;
if (m_requestStream.m_Socket != null)
{
this.m_requestStream.m_Socket.Close();
}
}
throw new WebException("", se);
}
catch(Exception e)
{
throw new WebException("", e);
}
return response;
}