title: Downloading a torrent file with WebClient, results in corrupt file
body: <p>I'm trying to download a .torrent file (not the contents of the torrent itself) in my .NET application.</p>
  
  <p>Using the following code works for other files, but not .torrent. The resulting files is about 1-3kb smaller than if I download the file via a browser. When opening it in a torrent client, it says the torrent is corrupt.</p>
  
  <pre><code>WebClient web = new WebClient();
  web.Headers.Add("Content-Type", "application/x-bittorrent");
  web.DownloadFile("http://kat.ph/torrents/linux-mint-12-gnome-mate-dvd-64-bit-t6008958/", "test.torrent");
  </code></pre>
  
  <p>Opening the URL in a browser results in the file being downloaded correctly.</p>
  
  <p>Any ideas as to why this would happen? Are there any good alternatives to WebClient that would download the file correctly?</p>
  
  <p>EDIT: I've tried this as well as WebClient, and it results in the same thing:</p>
  
  <pre><code>private void DownloadFile(string url, string file)
      {
          byte[] result;
          byte[] buffer = new byte[4096];
  
          WebRequest wr = WebRequest.Create(url);
          wr.ContentType = "application/x-bittorrent";
          using (WebResponse response = wr.GetResponse())
          {
              using (Stream responseStream = response.GetResponseStream())
              {
                  using (MemoryStream memoryStream = new MemoryStream())
                  {
                      int count = 0;
                      do
                      {
                          count = responseStream.Read(buffer, 0, buffer.Length);
                          memoryStream.Write(buffer, 0, count);
  
                      } while (count != 0);
  
                      result = memoryStream.ToArray();
  
                      using (BinaryWriter writer = new BinaryWriter(new FileStream(file, FileMode.Create)))
                      {
                          writer.Write(result);
                      }
                  }
              }
          }
      }
  </code></pre>