public Task<HttpResponseMessage> GetDotNetTeamRSS() { var server = ControllerContext.Request.RequestUri.GetLeftPart(UriPartial.Scheme | UriPartial.Authority); var client = new HttpClient(); return client.GetAsync(server + "/api/httpproxy?url=" + server + "/api/rss"); }
上面代码段如果你想验证返回值的时候就比较麻烦了,在以往可能需要这样
public Task<HttpResponseMessage> GetDotNetTeamRSS() { var server = ControllerContext.Request.RequestUri.GetLeftPart(UriPartial.Scheme | UriPartial.Authority); var client = new HttpClient(); var message = client.GetAsync(server + "/api/httpproxy?url=" + server + "/api/rss"); return message; }
貌似增加了一个IRandomAccessStream接口 可以干一些异步流加载绑定的事情,不是很明白应用场景,上代码
//access image via networking i/o var imageUrl = "http://www.microsoft.com/global/en-us/news/publishingimages/logos/MSFT_logo_Web.jpg"; var client = new HttpClient(); Stream stream = await client.GetStreamAsync(imageUrl); var memStream = new MemoryStream(); await stream.CopyToAsync(memStream); memStream.Position = 0; var bitmap = new BitmapImage(); bitmap.SetSource(memStream.AsRandomAccessStream()); image.Source = bitmap;读取网络资源绑定
//access image via file i/o var imagePath = "picture.png"; StorageFolder folder = KnownFolders.PicturesLibrary; StorageFile file = await folder.GetFileAsync(imagePath); var bitmap = new BitmapImage(); Stream stream = await file.OpenStreamForWriteAsync(); // this is the point where you operate on the stream with .NET code // imaging applying an image transform bitmap.SetSource(stream.AsRandomAccessStream()); image.Source = bitmap;读取本地资源绑定