当我点击 url 时:
https://youtu.be/rCiqxFuRi6o?rel=0&wmode=transparent
重定向到
https://www.youtube.com/watch?v=rCiqxFuRi6o&feature=youtu.be&rel=0&wmode=transparent
如何以编程方式从 Android 应用程序获取此重定向链接?
我终于想要获得 youtube 视频 ID。
最佳答案
当你连接到 https://youtu.be/rCiqxFuRi6o?rel=0&wmode=transparent
您将获得 http 302 状态(重定向):
HTTP/1.1 302 Found
Date: Thu, 07 May 2015 14:25:38 GMT
Server: gwiseguy/2.0
Location: https://www.youtube.com/watch?v=rCiqxFuRi6o&feature=youtu.be
Content-Length: 0
Content-Type: text/html
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
因此您只需要从 http 响应 header 中读取 Location header 即可。
关于java - 从短链接获取 youtube 重定向链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30103890/