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


C# WebException.ResponseString方法代码示例

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


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

示例1: parseException

        private Exception parseException(WebException e)
        {
            var code = e.HttpStatusCode();
            var message = e.ResponseString();

            JToken json = null;
            try { json = JToken.Parse(message); }
            catch (Exception) { }

            if(json != null && json["error"] != null)
            {
                message = (string)json["error"]["message"] + " (" + (string)json["error"]["code"] + ")";
            }

            if (code == 401) return new AuthorizationFailureException(message, e);
            return e;
        }
开发者ID:eliberis,项目名称:Diminuendo,代码行数:17,代码来源:SkydriveClient.cs

示例2: parseException

        private Exception parseException(WebException e)
        {
            string message = e.ResponseString();
            Nullable<int> code = e.HttpStatusCode();
            if (!string.IsNullOrEmpty(message)) message = (string)JObject.Parse(message)["error"];
            else message = string.Empty;
            if (code.HasValue) message += string.Format(" ({0})", code.Value);

            switch (code)
            {
                case 401:
                    // Unauthorized.
                    return new AuthorizationFailureException(message, e); 
                case 403:
                    // Forbidden.
                    return new FileConflictException(message, e);
                case 404:
                    // Not found.
                    return new FileNotFoundException(message, e);
                case 503: //TODO: implement delayed calling
                default:
                    if (code.HasValue && code / 100 == 5) return new ProviderNotAvailableException(message, e);
                    else return e;
            }
        }
开发者ID:eliberis,项目名称:Diminuendo,代码行数:25,代码来源:DropboxClient.cs


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