WP7调用API读取流时出错
public void LoadingData()
{
AndGoPage = NavigationContext.QueryString["AndGoPage"];
if (NavigationContext.QueryString.ContainsKey("cityName"))
{
cityName = NavigationContext.QueryString["cityName"];
}
client.OpenReadAsync(new Uri("http://php.weather.sina.com.cn/xml.php?city="+ cityName+"&password=DJOYnieT8234jlsK&day=0" , UriKind.RelativeOrAbsolute));
client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
}
void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
XElement xmlWeather;
try
{
xmlWeather = XElement.Load(e.Result.ToString());
}
catch (Exception)
{
MessageBox.Show("获取城市信息失败");
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));
return;
提示e.Result.ReadTimeout”引发了“System.InvalidOperationException”类型的异常
[解决办法]