简体   繁体   中英

Download file from a link that redirects c#

I'm quite new to C# and I need to download a file from this link: http://www.addic7ed.com/original/94097/1 the problem is that it keeps redirecting me to the page I got the url from. ( original url )

Couldn't manage to do it with WebClient neither with HttpWebRequest, but maybe its me doing something wrong. Any hints on how I could do this?

even tried this

edit: to be more specific, the url was supposed to download a .srt file and so it does when I click it on chrome. However, when I try to download the .srt file through c# I am being redirected and end up downloading the site's html source. How can I replicate chrome's behavior?

edit2: managed to do it by importing to webclient headers from a webbrowser. Still interested in other ways to do it, tho. This one seems durty to me.

This behaviour is happening on the server side, not the client side - ie, it's not a C# problem. I can get the URL you request fine using curl . Maybe try setting a different user-agent string on the WebClient or HttpWebRequest objects, if you can do that?

Looks like the link to the file is different it's: http://ewns-hls-b-cdn.hexaglobe.net/12914be14a5e488d8e028b7e4e0c0eab/55168b69/euronews_eng.smil/chunklist_b750000.m3u8 . It uses this link somewhere under the hood you can check all the call that browser performs via Fiddler and perform the same steps in c# code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM