-2

asp.net 4.0

I have googled for nearly a week now about this thing but couldn't find any solution to my problem.. I want to download files to store them on my server. I know about using a webclient it does the job but only for direct links

 webClient = new WebClient();
 webClient.DownloadFile(fileUrl, filePath);

it doesn't work for files which don't have direct links! how can I download these type of files?

direct link: www.example.com/pic.jpg

indirect links: www.example.com/download?xxxxxxx

the specific website on which I faced this problem is www.zbigz.com

you can get an indirect link by copying this link torrent link on www.zbigz.com and it will cache the file in a minute and will provide you the link under "free" category..

I do have a link generated by this site but it won't work for you as this site don't support downloading of shared link. http://34044.zbigz.com/core/outfile.php?did=d85ade21e892f386e55a556ce47b654b

edit For all those who think this is for scraping! I want to download those file but can't do that directly as my university has blocked many websites including this so being a cse student i thought of this another way of downloading them to my server and then to my machine from server.

        byte[] content;
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        WebResponse response = request.GetResponse();

        Stream stream = response.GetResponseStream();

        using (BinaryReader br = new BinaryReader(stream))
        {
            content = br.ReadBytes(500000);
            br.Close();
        }
        response.Close();

        FileStream fs = new FileStream(file_name, FileMode.Create);
        BinaryWriter bw = new BinaryWriter(fs);
        try
        {
            bw.Write(content);
        }
        finally
        {
            fs.Close();
            bw.Close();
        }

this is the code I am trying, works for direct link but gives 403 forbidden error on the above mentioned link.

4

1 に答える 1

1

使わないWebClientけど使うWebRequest

WebRequest はリダイレクトを自動的に処理できます。

WebRequest の派生元であるSystem.Net.WebRequest およびSystem.Net.HttpWebRequestを参照してください。

于 2013-01-28T15:01:48.380 に答える