private void Button_Click(object sender, RoutedEventArgs e) { string url = "http://localhost:30058/api/Products"; var uriStr = new Uri(url); var wc = new WebClient(); wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadStringAsyncCompleted); wc.DownloadStringAsync(uriStr); } void DownloadStringAsyncCompleted(object sender, DownloadStringCompletedEventArgs e) { try { lbResult.Content = e.Result; } catch (Exception ex) { lbResult.Content = ex.Message; } }
时间: 2024-10-12 13:20:10