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


C# WebException.GetBaseException方法代码示例

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


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

示例1: ParseWebException

        public static string ParseWebException(WebException webException)
        {
            if (webException == null)
                return string.Empty;

            var responseContent = GetResponseString(webException.Response);
            var response = webException.Response as HttpWebResponse;

            if (response != null)
                return string.Format(CultureInfo.InvariantCulture, "{0} {1}", response.StatusCode, responseContent).Trim();

            if (string.IsNullOrWhiteSpace(responseContent))
                return responseContent;

            return webException.GetBaseException().Message;
        }
开发者ID:wadewegner,项目名称:sdkMicrophoneCS_UploadToBlob,代码行数:16,代码来源:Helper.cs

示例2: TryWrapException

        /// <summary>
        /// Will attempt to wrap the exception, returning true if the exception was wrapped, or returning false if it was not (in which case
        /// the original exception should be thrown).
        /// </summary>
        /// <param name="requestContext"></param>
        /// <param name="webException"></param>
        /// <param name="wrappedException">The wrapped exception (will be set to the webException, if this method returns <c>false</c></param>
        /// <returns><c>true</c>, if the authException should be throw, <c>false</c> if the wrapped web exception should be thrown</returns>
        public static bool TryWrapException(IOAuthContext requestContext, WebException webException, out Exception wrappedException)
        {
            try
            {
                string content = webException.Response.ReadToEnd();

                if (content.Contains(Parameters.OAuth_Problem))
                {
                  var report = new OAuthProblemReport(content);
                  wrappedException = new OAuthException(report.ProblemAdvice ?? report.Problem, webException) { Context = requestContext, Report = report };
                }
                else
                {
                  wrappedException = new ParsedWebException(content, webException.Message, webException.GetBaseException(), webException.Status, webException.Response);
                }

                return true;
            }
            catch
            {
              wrappedException = webException;
              return false;
            }          
        }
开发者ID:tiwariritesh7,项目名称:devdefined-tools,代码行数:32,代码来源:WebExceptionHelper.cs

示例3: FillStatus

		private void FillStatus(ReplicationInfoStatus replicationInfoStatus, WebException e)
		{
			if (e.GetBaseException() is WebException)
				e = (WebException) e.GetBaseException();

			var response = e.Response as HttpWebResponse;
			if (response == null)
			{
				replicationInfoStatus.Status = e.Message;
				replicationInfoStatus.Code = -1 * (int)e.Status;
				return;
			}

			switch (response.StatusCode)
			{
				case HttpStatusCode.BadRequest:
					string error = GetErrorStringFromException(e, response);
					replicationInfoStatus.Status = error.Contains("Could not figure out what to do")
														   ? "Replication Bundle not activated."
														   : error;
					replicationInfoStatus.Code = (int)response.StatusCode;
					break;
				case HttpStatusCode.PreconditionFailed:
					replicationInfoStatus.Status = "Could not authenticate using OAuth's API Key";
					replicationInfoStatus.Code = (int)response.StatusCode;
					break;
				case HttpStatusCode.Forbidden:
				case HttpStatusCode.Unauthorized:
					replicationInfoStatus.Status = "Could not authenticate using Windows Auth";
					replicationInfoStatus.Code = (int)response.StatusCode;
					break;
				default:
					replicationInfoStatus.Status = response.StatusDescription;
					replicationInfoStatus.Code = (int)response.StatusCode;
					break;
			}
		}
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:37,代码来源:AdminReplicationController.cs

示例4: ParseStringWebException

        public static Exception ParseStringWebException(WebException webException)
        {
            if (webException == null)
            {
                return null;
            }

            try
            {
                var serializer = new DataContractSerializer(typeof(string));
                var stream = webException.Response.GetResponseStream();
                var errorMessage = serializer.ReadObject(stream) as string;

                return new Exception(errorMessage);
            }
            catch
            {
                if (webException.Response is HttpWebResponse)
                {
                    var response = webException.Response as HttpWebResponse;
                    return new HttpWebException(
                        string.IsNullOrWhiteSpace(response.StatusDescription) ? webException.Message : response.StatusDescription,
                        response.StatusCode,
                        webException);
                }
                else
                {
                    return webException.GetBaseException();
                }
            }
        }
开发者ID:junleqian,项目名称:Mobile-Restaurant,代码行数:31,代码来源:StorageClientExceptionParser.cs

示例5: ParseXmlWebException

        public static Exception ParseXmlWebException(WebException webException)
        {
            if (webException == null)
            {
                return null;
            }

            try
            {
                var stream = webException.Response.GetResponseStream();
                var streamReader = new StreamReader(stream);
                var doc = XDocument.Parse(streamReader.ReadToEnd());

                return ParseXmlExceptionDocument(doc.Root);
            }
            catch
            {
                if (webException.Response is HttpWebResponse)
                {
                    var response = webException.Response as HttpWebResponse;
                    return new HttpWebException(
                        string.IsNullOrWhiteSpace(response.StatusDescription) ? webException.Message : response.StatusDescription,
                        response.StatusCode,
                        webException);
                }
                else
                {
                    return webException.GetBaseException();
                }
            }
        }
开发者ID:junleqian,项目名称:Mobile-Restaurant,代码行数:31,代码来源:StorageClientExceptionParser.cs


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