zoukankan      html  css  js  c++  java
  • HttpWebRequest BeginGetResponse EndGetResponse

            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);
            }
  • 相关阅读:
    python RabbitMQ gRPC 实践经验
    python 数据库实践经验
    python GUI相关
    angularjs中的$watch、$digest、$apply
    css选择器优先级
    angularjs基本理解
    如何编写符合web标准的XHTML文档
    跨域问题
    如何养成良好的书写代码习惯
    ie常见兼容问题
  • 原文地址:https://www.cnblogs.com/grj1046/p/3242380.html
Copyright © 2011-2022 走看看