Issue with Downloading Torrent Files Using Webclient
I am trying to build a app that will download torrent files. While it downloads it seems not to save files correctly.
It seems to have a missing header or something. If you open the file you don't see the tracker's info. The file is about 1 KB to 3 KB smaller than if I download it from browser.
I figured it has to be mime-file type issue because I replaced torrent link with some image on Google and it downloads fine.
private v开发者_运维问答oid submitButton_Click(object sender, EventArgs e)
{
string hashCodeString;
hashCodeString = hashTextBox.Text;
addressTextBox.Text = "http://www.torrage.com/torrent/" + hashCodeString +".torrent";
torrageLinkLabel.Text = addressTextBox.Text;
}
private void torrageLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
using (var client = new WebClient())
{
client.DownloadFile(torrageLinkLabel.Tex… @"C:\torrent\file.torrent");
}
Not sure why it's missing the header and trackers.
I'm having this problem as well. I think I've narrowed it down to the redirection to the torrent cache site which sits behind SSL. If you open Fiddler and configure it to decrypt SSL traffic, then execute your WebClient.Download section of code, you should get all header/tracker data.
But the minute you close Fiddler and that traffic is not decrypted, the header/tracker data doesn't come down anymore.
Not sure how to get around this problem.
Found the answer to this... The responses are using gzip compression. All you need to do is add the following lines to your web request:
request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
精彩评论