An exception of type 'System.Net.WebException'

会有一股神秘感。 提交于 2021-02-11 17:00:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!