From 3be3b53c7743834f1babcadb39521af3fe8b71a6 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Sun, 10 Jul 2022 17:47:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E5=8A=A8=E5=A4=84=E7=90=86302?= =?UTF-8?q?=E3=80=81302=EF=BC=8C=E9=98=B2=E6=AD=A2headers=E4=B8=A2?= =?UTF-8?q?=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE.Common/Util/HTTPUtil.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/N_m3u8DL-RE.Common/Util/HTTPUtil.cs b/src/N_m3u8DL-RE.Common/Util/HTTPUtil.cs index 6197d76..14e4f99 100644 --- a/src/N_m3u8DL-RE.Common/Util/HTTPUtil.cs +++ b/src/N_m3u8DL-RE.Common/Util/HTTPUtil.cs @@ -26,7 +26,7 @@ namespace N_m3u8DL_RE.Common.Util public static readonly HttpClient AppHttpClient = new(new HttpClientHandler { - AllowAutoRedirect = true, + AllowAutoRedirect = false, AutomaticDecompression = DecompressionMethods.All, ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true }) @@ -49,7 +49,17 @@ namespace N_m3u8DL_RE.Common.Util } } Logger.Debug(webRequest.Headers.ToString()); - var webResponse = (await AppHttpClient.SendAsync(webRequest, HttpCompletionOption.ResponseHeadersRead)).EnsureSuccessStatusCode(); + var webResponse = await AppHttpClient.SendAsync(webRequest, HttpCompletionOption.ResponseHeadersRead); + if (webResponse.StatusCode == HttpStatusCode.Found || webResponse.StatusCode == HttpStatusCode.Moved) + { + HttpResponseHeaders respHeaders = webResponse.Headers; + Logger.Debug(respHeaders.ToString()); + if (respHeaders != null && respHeaders.Location != null) + { + var redirectedUrl = respHeaders.Location.AbsoluteUri; + return await DoGetAsync(redirectedUrl, headers); + } + } return webResponse; }