优化location读取

This commit is contained in:
nilaoda 2022-09-18 19:45:56 +08:00
parent 005d012558
commit ce112208d4
1 changed files with 17 additions and 3 deletions

View File

@ -55,12 +55,26 @@ namespace N_m3u8DL_RE.Common.Util
{
HttpResponseHeaders respHeaders = webResponse.Headers;
Logger.Debug(respHeaders.ToString());
if (respHeaders != null && respHeaders.Location != null && respHeaders.Location.AbsoluteUri != url)
if (respHeaders != null && respHeaders.Location != null)
{
var redirectedUrl = "";
if (!respHeaders.Location.IsAbsoluteUri)
{
Uri uri1 = new Uri(url);
Uri uri2 = new Uri(uri1, respHeaders.Location);
redirectedUrl = uri2.ToString();
}
else
{
redirectedUrl = respHeaders.Location.AbsoluteUri;
}
if (redirectedUrl != url)
{
var redirectedUrl = respHeaders.Location.AbsoluteUri;
return await DoGetAsync(redirectedUrl, headers);
}
}
}
//手动将跳转后的URL设置进去, 用于后续取用
webResponse.Headers.Location = new Uri(url);
webResponse.EnsureSuccessStatusCode();