本文整理汇总了C#中HttpClient.GetInputStreamAsync方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.GetInputStreamAsync方法的具体用法?C# HttpClient.GetInputStreamAsync怎么用?C# HttpClient.GetInputStreamAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpClient
的用法示例。
在下文中一共展示了HttpClient.GetInputStreamAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConnectToClient
/// <summary>
/// Connects to client.
/// </summary>
/// <returns></returns>
protected override async Task ConnectToClient()
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new Windows.Web.Http.Headers.HttpCredentialsHeaderValue("Bearer", accessToken);
using (var result = await client.GetInputStreamAsync(streamUri))
{
using (var s = result.AsStreamForRead())
{
await ListensToStreamAsync(s);
}
}
}
}
示例2: downloadPdf
private async void downloadPdf(String urlLink)
{
HttpClient client = new HttpClient();
using (IInputStream inputStream = await client.GetInputStreamAsync(new Uri("http://www.viser.edu.rs/"+urlLink, UriKind.Absolute)))
{
Stream webStream = inputStream.AsStreamForRead();
StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("2.pdf", CreationCollisionOption.ReplaceExisting);
// StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.CreateFileAsync("2.pdf",CreationCollisionOption.ReplaceExisting);
Stream fileStream = await file.OpenStreamForWriteAsync();
await webStream.CopyToAsync(fileStream);
//MessageDialog md = new MessageDialog("File Saved");
//await md.ShowAsync();
webStream.Dispose();
fileStream.Dispose();
}
}
示例3: getImage
private async void getImage(object sender, object e)
{
var filter = new HttpBaseProtocolFilter();
filter.CacheControl.ReadBehavior = HttpCacheReadBehavior.MostRecent;
Uri BingImageXML = new Uri("http://cn.bing.com/HPImageArchive.aspx?idx=0&n=1");
HttpClient LinkToBing = new HttpClient(filter); //加了filter才会刷新HttpClient的内容
System.Xml.XmlDocument doc2 = new System.Xml.XmlDocument();
var BingStream = await LinkToBing.GetInputStreamAsync(BingImageXML);
doc2.Load(BingStream.AsStreamForRead()); //使用stream读取网页上的XML信息
XmlNodeList lis=doc2.GetElementsByTagName("url");
String str = lis[0].InnerText;
imgUrl = new Uri("http://cn.bing.com" + str);
BitmapImage BingBitmapImage = new BitmapImage(imgUrl);
image.Source = BingBitmapImage;
}