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; }
private void PostHttpCallback_Click(object sender, RoutedEventArgs e) { string url = "http://baike.baidu.com/cms/global/lemma_config.json"; Action <byte[], HttpStatusCode> callBack = (bytes, httpStatusCode) => { string res = Encoding.UTF8.GetString(bytes, 0, bytes.Length); var m = CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var x = new MessageDialog("请求状态码:" + httpStatusCode.ToString()).ShowAsync(); this.result_tbk.Text = res; }); }; NetworkRequest.Post(url, "name=123", callBack); }
private async void PostHttpRequest_Sync_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(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; }