开发者

C# System.Net WebClient.DownloadData - Error retrieving proper data

开发者 https://www.devze.com 2023-03-16 19:03 出处:网络
Perhaps the main issue is where I am uploading to - I am currently using MediaFire to upload my files. I have tested with downloading files of both \".exe\" as 开发者_如何学Pythonwell as \".png\" form

Perhaps the main issue is where I am uploading to - I am currently using MediaFire to upload my files. I have tested with downloading files of both ".exe" as 开发者_如何学Pythonwell as ".png" formats; neither seem to work for me though.

The issue that is constantly occurring for me:

When I attempt to download a file, (I will put the URL's of the two files at the end of my question), the amount of data retrieved is either far greater - or far less than the actual size of the file. For example, I uploaded a blank VB6 executable file which is 16kb. The downloaded file comes out to be nearly 60 kilobytes!

Some things to note:

1) Both files download with no problems through Chrome (and I'm assuming other browsers as well).

2) I have tried multiple methods of retrieving the data from the downloaded file (same result).

My Code:

    // Create a new instance of the System.Net 'WebClient'
    System.Net.WebClient client = new System.Net.WebClient();

    // Download URL

    // PNG File
    string url = @"http://www.mediafire.com/imageview.php?quickkey=a16mo8gm03fv1d9&thumb=4";

    // EXE File (blank VB6 exe file @ 16kb)
    //  string url = @"http://www.mediafire.com/download.php?nn1cupi7j5ia7cb";

    // Destination
    string savePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\Test.png";

    byte[] result = client.DownloadData(url);

    MessageBox.Show(result.Length.ToString());   // Returns 57,000 something (over 3x larger than my EXE file!).

    // Write downloaded data to desired destination
    System.IO.File.WriteAllBytes(savePath, result);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号