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


C# HttpWebRequest.GetConnectingContext方法代码示例

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


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

示例1: CompleteConnection

        private void CompleteConnection(bool async, HttpWebRequest request)
        {
            GlobalLog.Enter("Connection#" + ValidationHelper.HashString(this) + "::CompleteConnection", "async:" + async.ToString() + " request:" + ValidationHelper.HashString(request));
            GlobalLog.ThreadContract(ThreadKinds.Unknown, "Connection#" + ValidationHelper.HashString(this) + "::CompleteConnection");

            WebExceptionStatus ws = WebExceptionStatus.ConnectFailure;
            //
            // From now on the request.SetRequestSubmitDone must be called or it may hang
            // For a [....] request the write side reponse windowwas opened in HttpWebRequest.SubmitRequest
            if (request.Async)
                request.OpenWriteSideResponseWindow();

            try
            {
                try {
#if !FEATURE_PAL
                    if (request.Address.Scheme == Uri.UriSchemeHttps) {
                        TlsStream tlsStream = new TlsStream(request.GetRemoteResourceUri().IdnHost,
                            NetworkStream, request.ClientCertificates, ServicePoint, request,
                            request.Async ? request.GetConnectingContext().ContextCopy : null);
                        NetworkStream = tlsStream;
                    }
#endif
                    ws = WebExceptionStatus.Success;
                }
                catch {
                    // The TLS stream could not be created.  Close the current non-TLS stream immediately
                    // to prevent any future use of it.  Due to race conditions, the error handling will sometimes
                    // try to write (flush) out some of the HTTP headers to the stream as it is closing down the failed 
                    // HttpWebRequest. This would cause plain text to go on the wire even though the stream should
                    // have been TLS encrypted.
                    NetworkStream.Close();
                    throw;
                }
                finally {
                    //
                    // There is a ---- with Abort so TlsStream ctor may throw.
                    // SetRequestSubmitDone will deal with this kind of errors.
                    // 

                    m_ReadState = ReadState.Start;
                    ClearReaderState();

                    request.SetRequestSubmitDone(new ConnectStream(this, request));
                }
            }
            catch (Exception exception)
            {
                if (m_InnerException == null)
                    m_InnerException = exception;
                WebException webException = exception as WebException;
                if (webException != null)
                {
                    ws = webException.Status;
                }
            }

            if (ws != WebExceptionStatus.Success)
            {
                ConnectionReturnResult returnResult = null;
                HandleError(false, false, ws, ref returnResult);
                ConnectionReturnResult.SetResponses(returnResult);

                if (Logging.On) Logging.PrintError(Logging.Web, this, "CompleteConnection", "on error");
                GlobalLog.Leave("Connection#" + ValidationHelper.HashString(this) + "::CompleteConnection", "on error");
            }
            else
            {
                GlobalLog.Leave("Connection#" + ValidationHelper.HashString(this) + "::CompleteConnection");
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:71,代码来源:_Connection.cs

示例2: CompleteConnection

 private void CompleteConnection(bool async, HttpWebRequest request)
 {
     WebExceptionStatus connectFailure = WebExceptionStatus.ConnectFailure;
     if (request.Async)
     {
         request.OpenWriteSideResponseWindow();
     }
     try
     {
         try
         {
             if (request.Address.Scheme == Uri.UriSchemeHttps)
             {
                 TlsStream stream = new TlsStream(request.GetRemoteResourceUri().Host, base.NetworkStream, request.ClientCertificates, this.ServicePoint, request, request.Async ? request.GetConnectingContext().ContextCopy : null);
                 base.NetworkStream = stream;
             }
         }
         finally
         {
             this.m_ReadState = ReadState.Start;
             this.ClearReaderState();
             request.SetRequestSubmitDone(new ConnectStream(this, request));
             connectFailure = WebExceptionStatus.Success;
         }
     }
     catch (Exception exception)
     {
         if (this.m_InnerException == null)
         {
             this.m_InnerException = exception;
         }
         WebException exception2 = exception as WebException;
         if (exception2 != null)
         {
             connectFailure = exception2.Status;
         }
     }
     if (connectFailure != WebExceptionStatus.Success)
     {
         ConnectionReturnResult returnResult = null;
         this.HandleError(false, false, connectFailure, ref returnResult);
         ConnectionReturnResult.SetResponses(returnResult);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:44,代码来源:Connection.cs


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