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


C# WebException.ToString方法代码示例

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


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

示例1: HandleConnection

        private static void HandleConnection(WebException ex)
        {
            Log.Error(ex);
            StatusNotification.Notify("Connection failed");

            if (ex.Status == WebExceptionStatus.NameResolutionFailure)
            {
                MessageBox.Show("Could not find the server. Please check the URL.", "Connection failed", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else if ( ex.Response is HttpWebResponse)
            {
                var response = (HttpWebResponse)ex.Response;

                switch (response.StatusCode)
                {
                    case HttpStatusCode.BadGateway:
                        MessageBox.Show("Could not find the server. Please check the URL.", "Connection failed", MessageBoxButton.OK, MessageBoxImage.Information);
                        break;
                    case HttpStatusCode.Unauthorized:
                    case HttpStatusCode.Forbidden:
                        MessageBox.Show("You are not authorized to open this site", "Connection failed", MessageBoxButton.OK, MessageBoxImage.Information);
                        break;
                    default:
                        MessageBox.Show(ex.Message, "Connection failed", MessageBoxButton.OK, MessageBoxImage.Information);
                        break;
                }
            }
            else
                MessageBox.Show(ex.ToString(), "Connection failed", MessageBoxButton.OK, MessageBoxImage.Information);
        }
开发者ID:konradsikorski,项目名称:smartCAML,代码行数:30,代码来源:ExceptionHandler.cs

示例2: Log

 public static void Log(WebException webException, ref string strErrors)
 {
     string strContext = webException.ToString();
     var errorStream = webException.Response.GetResponseStream();
     DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ODataError));
     ODataError getError = (ODataError)(ser.ReadObject(errorStream));
     string strCode = getError.error.code;
     string strDetail = getError.error.message.value;
     strErrors += strDetail;
     GraphHelperEventSource.Log.WebFailure(strContext, strCode, strDetail);
 }
开发者ID:mebarron,项目名称:WebApp-GraphAPI-DirectoryExtensions-DotNet,代码行数:11,代码来源:EventSource.cs

示例3: RestResponse

 public RestResponse(WebException ex)
 {
     this.ErrorStatus = ex.Status;
     this.CompleteErrorMessage = ex.ToString();
     using (HttpWebResponse resp = (HttpWebResponse)ex.Response)
     {
         if (resp != null)//is null if no connection or timeout etc.
         {
             this.StatusCode = resp.StatusCode;
             this.Content = GetContent(resp);
         }
     }
 }
开发者ID:cannero,项目名称:restlib,代码行数:13,代码来源:RestResponse.cs

示例4: ProcessWebException

 private static void ProcessWebException(WebException e)
 {
     Console.WriteLine("{0}", e.ToString());
     string strResponse = string.Empty;
     using (HttpWebResponse response = (HttpWebResponse)e.Response)
     {
         using (Stream responseStream = response.GetResponseStream())
         {
             using (StreamReader sr = new StreamReader(responseStream, System.Text.Encoding.ASCII))
             {
                 strResponse = sr.ReadToEnd();
             }
         }
     }
     Console.WriteLine("Http status code={0}, error message={1}", e.Status, strResponse);
 }
开发者ID:miguelahc,项目名称:MyApiMovie,代码行数:16,代码来源:Translator.cs

示例5: GetErrorMessage

        private string GetErrorMessage(WebException e)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(e.ToString());

            // Obtain detailed error information
            string strResponse = string.Empty;
            using (HttpWebResponse response = (HttpWebResponse)e.Response)
            {
                using (Stream responseStream = response.GetResponseStream())
                {
                    using (StreamReader sr = new StreamReader(responseStream, System.Text.Encoding.ASCII))
                    {
                        strResponse = sr.ReadToEnd();
                    }
                }
            }
            sb.AppendLine("Http status code=" + e.Status + ", error message=" + strResponse);

            return sb.ToString();
        }
开发者ID:moyoron64,项目名称:eyeX,代码行数:21,代码来源:TranslatorApi.cs

示例6: Log

 private void Log(WebException ex)
 {
     var logger = LogManager.GetLogger(typeof(TableStorageRequest));
     if(logger != null) logger.Error(ex.ToString());
 }
开发者ID:yvesgoeleven,项目名称:NHibernate.Windows.Azure.Storage.Driver,代码行数:5,代码来源:TableStorageRequest.cs

示例7: InternalHandle

 /// <summary>
 /// Internals the handle.
 /// </summary>
 /// <param name="ex">The executable.</param>
 /// <returns></returns>
 private ErrorAction InternalHandle(WebException ex)
 {
     return new ErrorAction(ErrorActionType.Retry, -2147204346, ex.ToString());
 }
开发者ID:udbeeq5566,项目名称:ESB,代码行数:9,代码来源:WebErrorHandler.cs

示例8: ExceptionToString

 private string ExceptionToString(WebException webException)
 {
     //ToDo : Build web exception
     return webException.ToString();
 }
开发者ID:RaringCoder,项目名称:Crucial-CQRS,代码行数:5,代码来源:Logger.cs

示例9: ProcessWebException

        private string ProcessWebException(WebException e, string message)
        {
            Console.WriteLine("{0}: {1}", message, e.ToString());

            // Obtain detailed error information
            string strResponse = string.Empty;
            using (HttpWebResponse response = (HttpWebResponse)e.Response)
            {
                using (Stream responseStream = response.GetResponseStream())
                {
                    using (StreamReader sr = new StreamReader(responseStream, System.Text.Encoding.ASCII))
                    {
                        strResponse = sr.ReadToEnd();
                    }
                }
            }
            return String.Format("Http status code={0}, error message={1}", e.Status, strResponse);
        }
开发者ID:patrickporter,项目名称:MT-Enhanced-Trados-Plugin,代码行数:18,代码来源:ApiConnecter.cs

示例10: HandleWebException

        private void HandleWebException(WebException we, HttpState httpState)
        {
            HttpStatusCode statusCode = GetErrorCode(we.Response as HttpWebResponse);

            // It hasn't an active INTERNET connection (resolve error),
            // or the connection was LOST after http request was sent (connect failure)
            // It disconnects automatically and stops. So you don't need to call Disconnect().
            if (we.Status == WebExceptionStatus.NameResolutionFailure ||
                we.Status == WebExceptionStatus.ProxyNameResolutionFailure ||
                we.Status == WebExceptionStatus.ConnectFailure ||
                we.Status == WebExceptionStatus.ProtocolError)
            {
                isWebRequestInProcess = false;
                Disconnect();

                OnConnectingException(we);
                return;
            }

            // If the session corrupted (BadRequest),
            // or the first http request (Open) is timed out then reconnect: We passed resolve/connect failures.
            // IMPORTANT: Don't send httpState.OutgoingData again...
            if (statusCode == HttpStatusCode.BadRequest ||
                (we.Status == WebExceptionStatus.Timeout && httpState.PollAction == HttpPollAction.Open))
            {
                isWebRequestInProcess = false;
                Disconnect();
                Connect();
                return;
            }

            switch (we.Status)
            {
                // If a soft error occurs, re-send the last packet.
                case WebExceptionStatus.ConnectionClosed:
                case WebExceptionStatus.PipelineFailure:
                case WebExceptionStatus.KeepAliveFailure:
                case WebExceptionStatus.Timeout:
                case WebExceptionStatus.SendFailure:
                case WebExceptionStatus.ReceiveFailure:
                    {
                        isWebRequestInProcess = false;

                        // IN MIDDLE SOFT ERROR
                        // Outgoing data wasn't sent, we can re-send...
                        if (httpState.OutgoingData != null && httpState.OutgoingData.Length > 0)
                        {
                            Send(httpState.OutgoingData, httpState.UserState);
                        }
                        else
                        {
                            // AT END SOFT ERROR
                            // Outgoing data was sent, but an error occured while closing (KeepAliveFailure)
                            // Anyway this is not fatal, next time we will send PNG...
                            return;
                        }
                    }
                    break;

                case WebExceptionStatus.SecureChannelFailure:
                    {
                        OnConnectionException(we);
                        goto default;
                    }

                case WebExceptionStatus.RequestCanceled:
                case WebExceptionStatus.UnknownError:
                default:
                    {
                        OnDisconnected();

                        Trace.WriteLineIf(Settings.TraceSwitch.TraceError,
                            "HTTP Error: " + we.ToString(), GetType().Name);

                        break;
                    }
            }
        }
开发者ID:quynh68,项目名称:msnp-sharp,代码行数:78,代码来源:HttpSocketMessageProcessor.cs

示例11: ProcessWebException

        private void ProcessWebException(WebException e, string message)
        {
            Debug.WriteLine("{0}: {1}", message, e.ToString());

            // Obtain detailed error information
            string strResponse = string.Empty;

            using (HttpWebResponse response = (HttpWebResponse)e.Response) {
                using (Stream responseStream = response.GetResponseStream()) {
                    using (StreamReader sr = new StreamReader(responseStream, System.Text.Encoding.UTF8)) {
                        strResponse = sr.ReadToEnd();
                    }
                }
            }

            Debug.WriteLine("Http status code={0}, error message={1}", e.Status, strResponse);

            if (Failure != null) {
                Failure(strResponse);
            }
        }
开发者ID:lhchavez,项目名称:poetamaldito,代码行数:21,代码来源:Speech.cs

示例12: LogException

 public static void LogException(WebException ex)
 {
     Trace.WriteLine("== BEGIN WebException =====================");
     Trace.WriteLine("Status: " + ex.Status);
     Trace.WriteLine(ex.ToString());
     HttpWebResponse response = ex.Response as HttpWebResponse;
     if (response != null)
         Trace.WriteLine(DumpResponse(response));
     Trace.WriteLine("== END WebException =======================");
 }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:10,代码来源:HttpRequestHelper.cs

示例13: LogThisError

 public void LogThisError(WebException e)
 {
     StringBuilder builder = new StringBuilder();
     builder.Append("Exception occured");
     builder.Append(string.Format("Exception Details : {0}", e.ToString()));
     LogThis(builder.ToString(), eloglevel.error);
 }
开发者ID:Mike0so,项目名称:PF-MAIL-OUTLOOK,代码行数:7,代码来源:Log.cs

示例14: HandleWebException

        private void HandleWebException(WebException ex)
        {
            var sb = new StringBuilder();
            sb.AppendLine("-------------Error-------------");

            sb.AppendLine(ex.ToString());

            sb.AppendLine("");


            using (var response = ex.Response)
            {
                try
                {
                    var httpResponse = (HttpWebResponse)response;
                    sb.AppendLine("-------------Message-------------");
                    sb.AppendLine(string.Format("StatusCode:{0}", httpResponse.StatusCode));
                    sb.AppendLine(string.Format("Status:{0}", httpResponse.StatusDescription));
                    using (var data = response.GetResponseStream())
                    {
                        var text = new StreamReader(data).ReadToEnd();
                        sb.AppendLine(text);
                    }
                }
                catch
                {
                }
            }
            sb.AppendLine("");

            outputTextBox.Text = sb.ToString();
        }
开发者ID:iprosoftware,项目名称:api-csharp-client,代码行数:32,代码来源:frmMain.cs

示例15: FromWebException

 internal static HttpException FromWebException(WebException webException) {
   try {
     GoogleEmailUploaderTrace.EnteringMethod(
         "HttpException.FromWebException");
     GoogleEmailUploaderTrace.WriteLine(
         "Exception ({0}): {1}",
         webException.Status.ToString(),
         webException.ToString());
     HttpResponse httpResponse = null;
     if (webException.Response != null) {
       GoogleEmailUploaderTrace.WriteLine(
           "Headers: {0}",
           webException.Response.Headers.ToString());
       httpResponse = new HttpResponse((HttpWebResponse)webException.Response);
     }
     HttpExceptionStatus httpExceptionStatus;
     switch (webException.Status) {
       case WebExceptionStatus.ProtocolError:
         if (webException.Response != null) {
           HttpStatusCode httpStatusCode =
               ((HttpWebResponse)webException.Response).StatusCode;
           if (httpStatusCode == HttpStatusCode.Unauthorized) {
             httpExceptionStatus = HttpExceptionStatus.Unauthorized;
             break;
           } else if (httpStatusCode == HttpStatusCode.Forbidden) {
             httpExceptionStatus = HttpExceptionStatus.Forbidden;
             break;
           } else if (httpStatusCode == HttpStatusCode.BadGateway) {
             httpExceptionStatus = HttpExceptionStatus.BadGateway;
             break;
           } else if (httpStatusCode == HttpStatusCode.Conflict) {
             httpExceptionStatus = HttpExceptionStatus.Conflict;
             break;
           } else if (httpStatusCode == HttpStatusCode.BadRequest) {
             httpExceptionStatus = HttpExceptionStatus.BadRequest;
             break;
           }
         }
         httpExceptionStatus = HttpExceptionStatus.ProtocolError;
         break;
       case WebExceptionStatus.Timeout:
         httpExceptionStatus = HttpExceptionStatus.Timeout;
         break;
       default:
         httpExceptionStatus = HttpExceptionStatus.Other;
         break;
     }
     return new HttpException(webException.Message,
                              httpExceptionStatus,
                              httpResponse);
   } finally {
     GoogleEmailUploaderTrace.ExitingMethod(
         "HttpException.FromWebException");
   }
 }
开发者ID:engrmostafijur,项目名称:google-email-uploader,代码行数:55,代码来源:HttpInterface.cs


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