本文整理汇总了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);
}
示例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);
}
示例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);
}
}
}
示例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);
}
示例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();
}
示例6: Log
private void Log(WebException ex)
{
var logger = LogManager.GetLogger(typeof(TableStorageRequest));
if(logger != null) logger.Error(ex.ToString());
}
示例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());
}
示例8: ExceptionToString
private string ExceptionToString(WebException webException)
{
//ToDo : Build web exception
return webException.ToString();
}
示例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);
}
示例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;
}
}
}
示例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);
}
}
示例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 =======================");
}
示例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);
}
示例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();
}
示例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");
}
}