private void Button_Click_4(object sender, RoutedEventArgs e) { HttpWebRequest request = HttpWebRequest.CreateHttp("http://www.example.com"); //request.Headers["UserAgent"] request.Method = "GET"; request.BeginGetResponse(callback, request); } private async void callback(IAsyncResult asyncResult) { //var httpWebResponse = request.EndGetResponse(asyncResult) as HttpWebRequest; var request = asyncResult.AsyncState as HttpWebRequest; var response = request.EndGetResponse(asyncResult); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8); string json = reader.ReadToEnd(); await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { txtResult.Text = json; }); }
private void Button_Click_4(object sender, RoutedEventArgs e) { HttpWebRequest request = HttpWebRequest.CreateHttp("http://www.example.com"); //request.Headers["UserAgent"] request.Method = "GET"; request.BeginGetResponse(async (asyncResult) => { //var httpWebResponse = request.EndGetResponse(asyncResult) as HttpWebRequest; var response = request.EndGetResponse(asyncResult); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8); string json = reader.ReadToEnd(); await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { txtResult.Text = json; }); }, request); }