问题
I'm working on WP7-8 application which is using RestClient for getting info from WebServer. When I swich off internet connection I see:
An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary
What does it mean? How or should I fix it? My code:
RestSharp.RestClient _client;
_client = new RestClient { BaseUrl = BaseURL };
_client.Timeout = 50;
resourceString = "Http:\\blablabla";
var request = new RestRequest { RequestFormat = DataFormat.Xml, Resource = resourceString };
request.Timeout = 50;
request.IncreaseNumAttempts();
if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable() != true)
{
ErrorCallback("Internet connection Error");
return;
}
_client.ExecuteAsync(request, response =>
{
return response;
}
回答1:
That exception is a TimeoutException
. You must increase the Timeout
property in order to let it complete the request, let's say to set it to 4000.
回答2:
Here is the gist of the problem - the WebException
is a generic way to tell you that something went wrong with the connection without necessarily telling you what it is. It is all-encompassing, if you want to look at it this way.
To actually get the reason the problem showed up, you will need to read the response inside the catch
block - the server will give you more details.
来源:https://stackoverflow.com/questions/18184271/an-exception-of-type-system-net-webexception