Ejemplo n.º 1
0
        private async void GetHttpRequest_Click(object sender, RoutedEventArgs e)
        {
            string url = "http://baike.baidu.com/cms/global/lemma_config.json";

            byte[] bytes = null;
            string str   = null;


            NetworkRequest request = NetworkRequest.CreateHttp("http://baike.baidu.com/cms/global/lemma_config.json?cl=2&rn=20&tn=news");

            bytes = request.Get();

            request = NetworkRequest.CreateHttp("http://p5.sinaimg.cn/2776321060/180/73181353913818");
            bytes   = await request.GetAsync();

            str             = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
            this.img.Source = await ToolsLib.Utility.GetBitmapImageAsync(bytes);

            request      = NetworkRequest.CreateHttp(url);
            request.Body = "name=123";
            bytes        = request.Post();

            request = NetworkRequest.CreateHttp(url);
            bytes   = await request.PostAsync();

            str = Encoding.UTF8.GetString(bytes, 0, bytes.Length);

            this.result_tbk.Text = str;
        }
Ejemplo n.º 2
0
        public Task <string> m()
        {
            TaskCompletionSource <string> task = new TaskCompletionSource <string>();

            Task.Run(async() =>
            {
                string str             = null;
                NetworkRequest request = NetworkRequest.CreateHttp("http://baike.baidu.com/cms/global/lemma_config.json");
                str = await request.GetAsync <string>();
                task.SetResult(str);
            });
            return(task.Task);
        }
Ejemplo n.º 3
0
        private async void GetHttpRequest_Async_Click(object sender, RoutedEventArgs e)
        {
            //byte[] bytes = null;
            //string str = null;
            //HttpRequest request = HttpRequest.CreatHttp("http://p5.sinaimg.cn/2776321060/180/73181353913818");
            //bytes = await request.GetAsync();
            //str = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
            //this.img.Source = await ToolsLib.Utility.GetBitmapImageAsync(bytes);

            NetworkRequest request = NetworkRequest.CreateHttp("http://p5.sinaimg.cn/2776321060/180/73181353913818");

            //this.img.Source = await request.GetBitmapImageAsync();
            this.img.Source = await request.GetAsync <BitmapImage>();
        }