soundcloudwpftoolkit

How do I get the redirect url?


I want to get a redirect url from a url.

Url:

https://api.soundcloud.com/tracks/151935719/stream?client_id=

redirect url looks something like this:

https://ec-media.soundcloud.com/0fdDn45vb5t4.128.mp3?f10880d39085a94a0418a7ef69b03d522cd6dfee9399eeb9a522019d6afabf3e3c10bce51c30cbe03f40dfc788e191ee959a960c826c0a5de46a851702613b05f3906a2971&AWSAccessKeyId=AKIAJNIGGLK7XA7YZSNQ&Expires=1401521245&Signature=B3P8qLw1t%2BQ2oYQUEfpep9%2FULXg%3D

How do I get the redirect url so I can stream from this link?

I am using C# WPF and I am a newbie.

Thanks!!


Solution

  • It should be automatic with HttpWebRequest.AllowAutoRedirect:

    HttpWebRequest request = HttpWebRequest.CreateHttp(yourURI);
    request.AllowAutoRedirect = true;
    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
    {
        // Your code
    }
    

    However, the default value for AllowAutoRedirect is true, so, in general, you shouldn't even need to set it. Redirection is automatically handled:

    HttpWebRequest request = HttpWebRequest.CreateHttp(yourURI);
    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
    {
        // Your code
    }