“System.Net.WebException"类型的异常 [英] An exception of type 'System.Net.WebException'
问题描述
我正在开发 WP7-8 应用程序,该应用程序使用 RestClient 从 WebServer 获取信息.当我关闭互联网连接时,我看到:
I'm working on WP7-8 application which is using RestClient for getting info from WebServer. When I swich off internet connection I see:
System.Net.WebException"类型的异常发生在System.Windows.ni.dll 并且在托管/本机之前未处理边界
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;
}
推荐答案
该异常是 TimeoutException
.您必须增加 Timeout
属性才能让它完成请求,假设将其设置为 4000.
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.
这篇关于“System.Net.WebException"类型的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!