WebException.Status状态对应中文解释

Posted by baicai on April 10, 2014
    public static class WebExceptionExtensions
    {
        public static string GetStatusDescription(this WebException we)
        {
            switch (we.Status)
            {
                case WebExceptionStatus.Success:
                    return "未遇到任何错误。";
                case WebExceptionStatus.ConnectFailure:
                    return "未能在传输级联系到远程服务点。";
                case WebExceptionStatus.SendFailure:
                    return "未能将完整请求发送到远程服务器。";
                case WebExceptionStatus.RequestCanceled:
                    return "请求被取消";
                case WebExceptionStatus.Pending:
                    return "内部异步请求挂起。";
                case WebExceptionStatus.UnknownError:
                    return "发生未知类型的异常。";
                case WebExceptionStatus.MessageLengthLimitExceeded:
                    return "当发送请求或从服务器接收响应时,会接收到超出指定限制的消息。";
                case WebExceptionStatus.NameResolutionFailure:
                    return "名称解析服务未能解析主机名。";
                case WebExceptionStatus.ReceiveFailure:
                    return "没有从远程服务器接收到完整响应";
                case WebExceptionStatus.PipelineFailure:
                    return "该请求是管线请求,并且连接未接收到响应即被关闭。";
                case WebExceptionStatus.ProtocolError:
                    return "从服务器接收到的响应完成了,但它指示了一个协议级错误。";
                case WebExceptionStatus.ConnectionClosed:
                    return "连接被过早关闭。";
                case WebExceptionStatus.TrustFailure:
                    return "未能验证服务器证书。";
                case WebExceptionStatus.SecureChannelFailure:
                    return "使用 SSL 建立连接时发生错误。";
                case WebExceptionStatus.ServerProtocolViolation:
                    return "此服务器响应不是有效的 HTTP 响应。";
                case WebExceptionStatus.KeepAliveFailure:
                    return "指定 Keep-alive 标头的请求连接被意外关闭。";
                case WebExceptionStatus.Timeout:
                    return "服务器连接超时。";//在请求的超时期限内未收到任何响应。
                case WebExceptionStatus.ProxyNameResolutionFailure:
                    return "名称解析服务未能解析代理主机名。";
                default:
                    return "未分析的异常";
            }
        }
    }