当前位置: 首页>>代码示例>>C#>>正文


C# System.Net.Http.HttpClient.GetStreamAsync方法代码示例

本文整理汇总了C#中System.Net.Http.HttpClient.GetStreamAsync方法的典型用法代码示例。如果您正苦于以下问题:C# System.Net.Http.HttpClient.GetStreamAsync方法的具体用法?C# System.Net.Http.HttpClient.GetStreamAsync怎么用?C# System.Net.Http.HttpClient.GetStreamAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Http.HttpClient的用法示例。


在下文中一共展示了System.Net.Http.HttpClient.GetStreamAsync方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Refresh

		public async Task<bool> Refresh()
		{
			if (!RevistaController.Instance.RefreshLista(
				await LibHelper.GetHttpPageAsyncHelper(RevistaController.RevistaUrl)))
				return false;

			var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(PATHIMAGENS, CreationCollisionOption.OpenIfExists);
			if (folder == null)
				return false;
			using (var http = new System.Net.Http.HttpClient())
			{
				var ll = await folder.GetFilesAsync();
				foreach (var item in Lista.Where(x => ll.FirstOrDefault(y => y.Name.Equals(Path.GetFileName(x.ImgUrl.AbsolutePath))) == null))
				{
					var file = await folder.CreateFileAsync(Path.GetFileName(item.ImgUrl.AbsolutePath), CreationCollisionOption.ReplaceExisting);

					using (var str = await http.GetStreamAsync(item.ImgUrl))
					{
						str.CopyTo(await file.OpenStreamForWriteAsync());
					}
					item.ImgUrl = new Uri(file.Path);
				}
			}
			return true;
		}
开发者ID:pikax,项目名称:papreader,代码行数:25,代码来源:RevistaControllerWrapper.cs

示例2: FetchAllFiles

        public async Task<List<ISourceItem>> FetchAllFiles(BuildConfig config)
        {
            using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient()) {
                using (var stream = await client.GetStreamAsync(config.SourceUrl)) {
                    using (var fs = File.OpenWrite(zipFile)) {
                        await stream.CopyToAsync(fs);
                    }
                }
            }

            List<ISourceItem> files = new List<ISourceItem>();

            using (ZipFile zip = new ZipFile(zipFile)) {
                foreach (ZipEntry entry in zip)
                {
                    if (entry.IsDirectory)
                        continue;
                    using (var s = zip.GetInputStream(entry)) {
                        string filePath = zipFolder + "\\" + entry.Name;
                        FileInfo fi = new FileInfo(filePath);
                        if (!fi.Directory.Exists)
                        {
                            fi.Directory.Create();
                        }
                        using (FileStream fs = fi.OpenWrite()) {
                            await fs.CopyToAsync(s);
                        }

                        string fileName = System.IO.Path.GetFileName(filePath);

                        ZipSourceItem file = new ZipSourceItem { 
                            Url = filePath,
                            Name = System.IO.Path.GetFileName(filePath),
                            Folder = entry.Name.Substring(0,entry.Name.Length-fileName.Length),
                            IsDirectory = false
                        };
                        files.Add(file);
                    }                    
                }
            }

            var md5 = System.Security.Cryptography.MD5.Create();

            Parallel.ForEach(files, file => {
                ((ZipSourceItem)file).Version = Convert.ToBase64String(md5.ComputeHash(File.ReadAllBytes(file.Url)));
            });

            return files;
        }
开发者ID:neurospeech,项目名称:iis-ci,代码行数:49,代码来源:ZipSourceController.cs

示例3: getTexture

		/// <summary>
		/// attempts to get a texture for the image
		/// - first it will check the href for a png file name. If it finds one it will load it with the ContentManager passed in
		/// - next it will see if the href is a url and if so it will load it
		/// - next it checks for an embedded, base64 image. It will load that if it finds one
		/// </summary>
		/// <returns>The texture.</returns>
		/// <param name="content">Content.</param>
		public Texture2D getTexture( NezContentManager content )
		{
			if( _didAttemptTextureLoad || _texture != null )
				return _texture;

			// check for a url
			if( href.StartsWith( "http" ) )
			{
				using( var client = new System.Net.Http.HttpClient() )
				{
					var stream = client.GetStreamAsync( href ).Result;
					_texture = Texture2D.FromStream( Core.graphicsDevice, stream );
				}
			}
			// see if we have a path to a png files in the href
			else if( href.EndsWith( "png" ) )
			{
				// check for existance before attempting to load! We are a PCL so we cant so we'll catch the Exception instead
				try
				{
					if( content != null )
						_texture = content.Load<Texture2D>( href );
				}
				catch( ContentLoadException )
				{
					Debug.error( "Could not load SvgImage from href: {0}", href );
				}
			}
			// attempt to parse the base64 string if it is embedded in the href
			else if( href.StartsWith( "data:" ) )
			{
				var startIndex = href.IndexOf( "base64,", StringComparison.OrdinalIgnoreCase ) + 7;
				var imageContents = href.Substring( startIndex );
				var bytes = Convert.FromBase64String( imageContents );

				using( var m = new MemoryStream() )
				{
					m.Write( bytes, 0, bytes.Length );
					m.Seek( 0, SeekOrigin.Begin );

					_texture = Texture2D.FromStream( Core.graphicsDevice, m );
				}
			}

			_didAttemptTextureLoad = true;
			return _texture;
		}
开发者ID:prime31,项目名称:Nez,代码行数:55,代码来源:SvgImage.cs

示例4: GetPackageFromCacheOrDownloadIt

        /// <summary>
        /// Look for the INupkg instance in the cache first. If it's in the cache, return it.
        /// Otherwise, download the package from the storage service and store it into the cache.
        /// </summary>
        public static async Task<INupkg> GetPackageFromCacheOrDownloadIt(
            Package package,
            IPackageCacheService cacheService,
            IPackageFileService packageFileService)
        {
            Debug.Assert(package != null);
            Debug.Assert(cacheService != null);
            Debug.Assert(packageFileService != null);

            string cacheKey = CreateCacheKey(package.PackageRegistration.Id, package.Version);
            byte[] buffer = cacheService.GetBytes(cacheKey);
            if (buffer == null)
            {
                // In the past, some very old packages can specify an external package binary not hosted at nuget.org.
                // We no longer allow that today.
                if (!String.IsNullOrEmpty(package.ExternalPackageUrl))
                {
                    var httpClient = new HttpClient();
                    using (var responseStream = await httpClient.GetStreamAsync(package.ExternalPackageUrl))
                    {
                        buffer = responseStream.ReadAllBytes();
                    }
                }
                else
                {
                    using (Stream stream = await packageFileService.DownloadPackageFileAsync(package))
                    {
                        if (stream == null)
                        {
                            throw new InvalidOperationException("Couldn't download the package from the storage.");
                        }

                        buffer = stream.ReadAllBytes();
                    }
                }

                cacheService.SetBytes(cacheKey, buffer);
            }

            return new Nupkg(new MemoryStream(buffer), leaveOpen: false);
        }
开发者ID:rajwilkhu,项目名称:NuGetGallery,代码行数:45,代码来源:PackageHelper.cs

示例5: Start

		public override void Start()
		{
			base.Start();


			IRelativePanel panel = Platform.Current.Create<IRelativePanel>();
			panel.BackgroundColor = new Color (255, 255, 255, 255);

			IGrid grdMenu = Constantes.CrearMenuVacio();
			panel.Add(grdMenu, RelativePanelHorizontalContraint.LeftWith, RelativePanelVerticalContraint.TopWith);

			IImageButton imgHome = Platform.Current.Create<IImageButton>();
			imgHome.LoadFromUrl (new Uri("http://radioudg.okhosting.com/images/app-15.png"));
			imgHome.Click += cmdHome_Click;
			grdMenu.SetContent(1, 0, imgHome);

			IImageButton imgRegionales = Platform.Current.Create<IImageButton>();
			imgRegionales.LoadFromUrl (new Uri("http://radioudg.okhosting.com/images-old/icon-11.png"));
			imgRegionales.Click += cmdEstaciones_Click;
			grdMenu.SetContent(1, 1, imgRegionales);

			IImageButton cmdProgramas = Platform.Current.Create<IImageButton>();
			cmdProgramas.LoadFromUrl (new Uri("http://radioudg.okhosting.com/images-old/icon-08.png"));
			//cmdProgramas.Click += (object sender, EventArgs e) => new ProgramasController().Start();
			grdMenu.SetContent(1, 2, cmdProgramas);

			IImageButton imgVirtuales = Platform.Current.Create<IImageButton>();
			imgVirtuales.LoadFromUrl (new Uri("http://radioudg.okhosting.com/images-old/icon-09.png"));
			imgVirtuales.Click += cmdVirtuales_Click;
			grdMenu.SetContent(1, 3, imgVirtuales);

			ILabel lblTitulo = Constantes.CrearTitulo("Archivo de programa", new Color(255, 255, 143, 0));
			panel.Add(lblTitulo, RelativePanelHorizontalContraint.LeftWith, RelativePanelVerticalContraint.BelowOf, grdMenu);

			if (Platform.Current.Page.Width > 250)
			{
				IImage imgLogo = Platform.Current.Create<IImage> ();
				imgLogo.LoadFromUrl (new Uri ("http://radioudg.okhosting.com/images-old/icon2--14.png"));
				imgLogo.Width = Platform.Current.Page.Width / 6;
				imgLogo.Height = lblTitulo.Height;
				imgLogo.Margin = new Thickness (0, 0, 10, 0);
				panel.Add(imgLogo, RelativePanelHorizontalContraint.RightWith, RelativePanelVerticalContraint.TopWith, lblTitulo);
			}

			System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
			var xmlStream = client.GetStreamAsync(Show.PodcastUri).Result;

			System.Xml.XmlReader reader = System.Xml.XmlReader.Create(xmlStream);

			IList<Episode> episodios = new List<Episode>();

			//extraer episodios del xml
			while (reader.ReadToFollowing ("item")) 
			{
				reader.ReadToFollowing ("title");
				Episode episodio = new Episode ();
				episodio.Name = reader.ReadElementContentAsString ();
				reader.ReadToFollowing ("link");
				string mp3string = reader.ReadElementContentAsString();
				episodio.EpisodeUri = new Uri (mp3string);
				episodio.ImagenUri = Show.LogoUri;
				episodio.Description = Show.Name;

				episodios.Add (episodio);
			}

			reader.Dispose();
			xmlStream.Dispose();
			client.Dispose();

			IControl referencia = lblTitulo;

			foreach (Episode episodio in episodios)
			{
				IImageButton imgLogo = Platform.Current.Create<IImageButton>();
				imgLogo.LoadFromUrl(Show.LogoUri);
				imgLogo.Click += Episode_Click;
				imgLogo.Tag = episodio;
				imgLogo.Width = Constantes.AnchoIconos;
				imgLogo.Height = Constantes.AnchoIconos;
				
				//set margin for first iteration
				if (referencia == lblTitulo)
				{
					imgLogo.Margin = new Thickness(10, 10, 10, 10);
				}
				else
				{
					imgLogo.Margin = new Thickness(0, 10, 10, 10);
				}

				panel.Add(imgLogo, RelativePanelHorizontalContraint.LeftWith, RelativePanelVerticalContraint.BelowOf, referencia);

				referencia = imgLogo;
				
				ILabelButton lblNombre = Platform.Current.Create<ILabelButton> ();
				lblNombre.Click += Episode_Click;
				lblNombre.Text = episodio.Name;
				lblNombre.Tag = episodio;
				lblNombre.Bold = true;
//.........这里部分代码省略.........
开发者ID:tobias2016,项目名称:OKHOSTING.UDG.Radio,代码行数:101,代码来源:PodcastsController.cs

示例6: LeerEstaciones

        public static List<Station> LeerEstaciones()
        {
            List<Station> estaciones = new List<Station>();
            System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
            var xmlStream = client.GetStreamAsync("http://radioudg.okhosting.com/virtuales.xml").Result;
            System.Xml.XmlReader reader = System.Xml.XmlReader.Create(xmlStream);

            //extraer episodios del xml
            while (reader.ReadToFollowing("estacion"))
            {
                Station estacion = new Station();

                reader.ReadToFollowing("imagen");
                estacion.WebSiteUri = new Uri(reader.ReadElementContentAsString());

                reader.ReadToFollowing("streaming");
                estacion.StramingUri = new Uri(reader.ReadElementContentAsString());
                
                reader.ReadToFollowing("nombre");
                estacion.Name = reader.ReadElementContentAsString();

                reader.ReadToFollowing("descripcion");
                estacion.Description = reader.ReadElementContentAsString();

                estaciones.Add(estacion);
            }

			reader.Dispose();
			xmlStream.Dispose();
			client.Dispose();

			return estaciones;
        }
开发者ID:tobias2016,项目名称:OKHOSTING.UDG.Radio,代码行数:33,代码来源:VirtualesController.cs

示例7: SetAttachment

        /// <summary>
        /// Sets the attachment.
        /// </summary>
        /// <remarks>
        /// Sets the attachment with the given name.  The <see cref="Couchbase.Lite.Attachment"/> data will be 
        /// written to the <see cref="Couchbase.Lite.Database"/> when the <see cref="Couchbase.Lite.Revision"/> is saved.
        /// </remarks>
        /// <param name="name">Name.</param>
        /// <param name="contentType">Content type.</param>
        /// <param name="contentUrl">Content URL.</param>
        public void SetAttachment(String name, String contentType, Uri contentUrl) {
            try
            {
                var http = new System.Net.Http.HttpClient();
				using (var inputStream = http.GetStreamAsync(contentUrl).Result) {	                
	                var length = inputStream.Length;
	                var inputBytes = inputStream.ReadAllBytes();
					#if !PORTABLE
	                inputStream.Close();
					#endif

					SetAttachment(name, contentType, inputBytes);
				}
            }
            catch (IOException e)
            {
                Log.E(Database.Tag, "Error opening stream for url: " + contentUrl);
                throw new RuntimeException(e);
            }
        }
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:30,代码来源:UnsavedRevision.cs

示例8: InitiateHttp

		public async Task InitiateHttp ()
		{
			var client = new System.Net.Http.HttpClient (new NativeMessageHandler ());
			RenderStream (await client.GetStreamAsync (WisdomUrl));
		}
开发者ID:IanLeatherbury,项目名称:NASA_POD,代码行数:5,代码来源:FirstViewController.cs


注:本文中的System.Net.Http.HttpClient.GetStreamAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。