我想从网址获取重定向网址。
地址:
https://api.soundcloud.com/tracks/151935719/stream?client_id=
重定向网址看起来像这样:
https://ec-media.soundcloud.com/0fdDn45vb5t4.128.mp3?f10880d39085a94a0418a7ef69b03d522cd6dfee9399eeb9a522019d6afabf3e3c10bce51c30cbe03f40dfc788e191ee959a960c826c0a5de46a851702613b05f3906a2971&AWSAccessKeyId=AKIAJNIGGLK7XA7YZSNQ&Expires=1401521245&Signature=B3P8qLw1t%2BQ2oYQUEfpep9%2FULXg%3D
如何获取重定向网址,以便我可以从此链接流式传输?
我正在使用C#WPF而且我是新手。
谢谢!
答案 0 :(得分:1)
它应该是HttpWebRequest.AllowAutoRedirect
的自动:
HttpWebRequest request = HttpWebRequest.CreateHttp(yourURI);
request.AllowAutoRedirect = true;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
// Your code
}
但是,AllowAutoRedirect
的默认值为true,因此,通常情况下,您甚至不需要设置它。重定向自动处理:
HttpWebRequest request = HttpWebRequest.CreateHttp(yourURI);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
// Your code
}