本文整理汇总了C#中System.Net.WebException.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# WebException.GetType方法的具体用法?C# WebException.GetType怎么用?C# WebException.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebException
的用法示例。
在下文中一共展示了WebException.GetType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckWebException
private void CheckWebException(WebException exception)
{
Trace.Call(exception == null ? null : exception.GetType());
switch (exception.Status) {
case WebExceptionStatus.ConnectFailure:
case WebExceptionStatus.ConnectionClosed:
case WebExceptionStatus.Timeout:
case WebExceptionStatus.ReceiveFailure:
case WebExceptionStatus.NameResolutionFailure:
case WebExceptionStatus.ProxyNameResolutionFailure:
// ignore temporarly issues
#if LOG4NET
f_Logger.Warn("CheckWebException(): ignored exception", exception);
#endif
return;
}
/*
http://apiwiki.twitter.com/HTTP-Response-Codes-and-Errors
* 200 OK: Success!
* 304 Not Modified: There was no new data to return.
* 400 Bad Request: The request was invalid. An accompanying error
* message will explain why. This is the status code will be
* returned during rate limiting.
* 401 Unauthorized: Authentication credentials were missing or
* incorrect.
* 403 Forbidden: The request is understood, but it has been
* refused. An accompanying error message will explain why.
* This code is used when requests are being denied due to
* update limits.
* 404 Not Found: The URI requested is invalid or the resource
* requested, such as a user, does not exists.
* 406 Not Acceptable: Returned by the Search API when an invalid
* format is specified in the request.
* 500 Internal Server Error: Something is broken. Please post to
* the group so the Twitter team can investigate.
* 502 Bad Gateway: Twitter is down or being upgraded.
* 503 Service Unavailable: The Twitter servers are up, but
* overloaded with requests. Try again later. The search and
* trend methods use this to indicate when you are being rate
* limited.
*/
HttpWebResponse httpRes = exception.Response as HttpWebResponse;
if (httpRes == null) {
throw exception;
}
switch (httpRes.StatusCode) {
case HttpStatusCode.BadGateway:
case HttpStatusCode.BadRequest:
case HttpStatusCode.Forbidden:
case HttpStatusCode.ServiceUnavailable:
case HttpStatusCode.GatewayTimeout:
// ignore temporarly issues
#if LOG4NET
f_Logger.Warn("CheckWebException(): ignored exception", exception);
#endif
return;
default:
throw exception;
}
}
示例2: HandleTwitterWebException
public void HandleTwitterWebException(WebException e, String prefix)
{
HttpWebResponse response = (HttpWebResponse)e.Response;
String protcol = (response == null) ? "" : "HTTP/" + response.ProtocolVersion;
String error = String.Empty;
//try reading JSON response
if (response != null && response.ContentType != null && response.ContentType.ToLower().Contains("json"))
{
try
{
StreamReader sin = new StreamReader(response.GetResponseStream());
String data = sin.ReadToEnd();
sin.Close();
Hashtable jdata = (Hashtable)JSON.JsonDecode(data);
if (jdata == null || !jdata.ContainsKey("error") ||
jdata["error"] == null || !jdata["error"].GetType().Equals(typeof(String)))
throw new Exception();
error = "Twitter Error: " + (String)jdata["error"] + ", ";
}
catch (Exception ex)
{
}
}
/* Handle Time-Out Gracefully */
if (e.Status.Equals(WebExceptionStatus.Timeout))
{
plugin.ConsoleException("Twitter " + prefix + " Request(" + protcol + ") timed-out");
return;
}
else if (e.Status.Equals(WebExceptionStatus.ProtocolError))
{
plugin.ConsoleException("Twitter " + prefix + " Request(" + protcol + ") failed, " + error + " " + e.GetType() + ": " + e.Message);
return;
}
else
throw e;
}
示例3: HandleWebException
protected ExtApiCallResult HandleWebException(WebException ex)
{
var httpResponse = (HttpWebResponse)ex.Response;
if (httpResponse != null)
{
return new ExtApiCallResult
{
StatusCode = httpResponse.StatusCode,
ResponseStream = httpResponse.GetResponseStream(),
FinalUrl = httpResponse.ResponseUri.AbsoluteUri
};
}
// else
var stream = new MemoryStream();
var msg = System.Text.Encoding.ASCII.GetBytes(string.Format("{0}: {1}", ex.GetType().ToString(), ex.Message));
stream.Write(msg, 0, msg.Length);
return new ExtApiCallResult
{
StatusCode = HttpStatusCode.NoContent,
ResponseStream = stream,
FinalUrl = httpResponse.ResponseUri.AbsoluteUri
};
}