Skip to main content
se añadieron 378 caracteres en el cuerpo
Origen Enlace
jtaborga
  • 1.1k
  • 6
  • 5
        public void RealizarPedido(string url)
        {
            string html = string.Empty;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);                

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                using (Stream stream = response.GetResponseStream())
                {
                    Byte[] info = stream.GetBytes(stream);    
                    
                    using (MemoryStreamFileStream memoryfile = new MemoryStreamFileStream(info"demo.aac", FileMode.Create, FileAccess.ReadWrite)){
                    {   file.Write(info, 0, info.Length);
                    }
    FileStream file = new FileStream("demo.aac", FileMode.Create, FileAccess.ReadWrite);      }
            }
       }

     file.Write  public byte[] GetBytes(info,Stream 0,source)
 info.Length      {
           if (source == null)
               throw new ArgumentNullException("source");
           if (source is MemoryStream)
           file    return (source as MemoryStream).CloseToArray();
           using (MemoryStream memoryStream = new MemoryStream())
           }{
                }source.CopyTo((Stream)memoryStream);
               return memoryStream.ToArray();
           }
       }
        public void RealizarPedido(string url)
        {
            string html = string.Empty;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);                

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                using (Stream stream = response.GetResponseStream())
                {
                    Byte[] info = stream.GetBytes();

                    using (MemoryStream memory = new MemoryStream(info))
                    {
                        FileStream file = new FileStream("demo.aac", FileMode.Create, FileAccess.ReadWrite);
                        file.Write(info, 0, info.Length);
                        file.Close();
                    }
                }
            }
       }
        public void RealizarPedido(string url)
        {
            string html = string.Empty;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);                

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                using (Stream stream = response.GetResponseStream())
                {
                    Byte[] info = GetBytes(stream);    
                    
                    using(FileStream file = new FileStream("demo.aac", FileMode.Create, FileAccess.ReadWrite)){
                       file.Write(info, 0, info.Length);
                    }
                }
            }
       }

       public byte[] GetBytes(Stream source)
       {
           if (source == null)
               throw new ArgumentNullException("source");
           if (source is MemoryStream)
               return (source as MemoryStream).ToArray();
           using (MemoryStream memoryStream = new MemoryStream())
           {
               source.CopyTo((Stream)memoryStream);
               return memoryStream.ToArray();
           }
       }
Origen Enlace
jtaborga
  • 1.1k
  • 6
  • 5

Comentarte que al convertir los bytes a caracteres en tu línea:

html = reader.ReadToEnd();

Puede que no sea la misma codificación (UTF8, UTF32) que manejas en tu aplicación por ejemplo y eso conlleva a que use otro símbolo (caracter) si no es encontrado en ese contexto de la codificación, lo recomendable es que lo guardes directamente usando un stream de Memoria MemoryStream y de ahí a un archivo si esa es tu intención.

        public void RealizarPedido(string url)
        {
            string html = string.Empty;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);                

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                using (Stream stream = response.GetResponseStream())
                {
                    Byte[] info = stream.GetBytes();

                    using (MemoryStream memory = new MemoryStream(info))
                    {
                        FileStream file = new FileStream("demo.aac", FileMode.Create, FileAccess.ReadWrite);
                        file.Write(info, 0, info.Length);
                        file.Close();
                    }
                }
            }
       }

Espero que te sirva.

Saludos.