From e37ffc302b936564204b71df2db294d7972326a2 Mon Sep 17 00:00:00 2001 From: rVinor Date: Thu, 21 Jul 2022 14:20:15 +0300 Subject: [PATCH 1/2] Fixed the HTTP 403 error preventing to load VITA DB database --- SHM/FormGetHomebrew.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/SHM/FormGetHomebrew.cs b/SHM/FormGetHomebrew.cs index 3f032e7..4805c0b 100644 --- a/SHM/FormGetHomebrew.cs +++ b/SHM/FormGetHomebrew.cs @@ -137,6 +137,7 @@ private void LoadVitadb_sync(string path, Action> result)// bool addD try { WebClient wc = new WebClient(); + wc.Headers.Add("User-Agent: Other"); string content = wc.DownloadString(new Uri(path)); wc.Dispose(); content = Encoding.UTF8.GetString(Encoding.Default.GetBytes(content)); From fbf61e267bad0e742bd20100ecfaba218177ce5a Mon Sep 17 00:00:00 2001 From: rVinor Date: Thu, 21 Jul 2022 14:44:38 +0300 Subject: [PATCH 2/2] Added "User-Agent: Other" header to avoid HTTP 403 error when downloading the VitaDB database --- SHM.Utilities/BrewProvider.cs | 6 +++++- SHM/FormGetHomebrew.cs | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/SHM.Utilities/BrewProvider.cs b/SHM.Utilities/BrewProvider.cs index 84f16e6..ac860d3 100644 --- a/SHM.Utilities/BrewProvider.cs +++ b/SHM.Utilities/BrewProvider.cs @@ -52,7 +52,11 @@ public async Task> RetrieveRawAsync(string source) public async Task> RetrieveRawFromVitaDbAsync(string source = null) { source = source ?? Constants.VitaDBBrewsListUri; - return await Try.ItAsync(async () => await source.GetJsonAsync>()) ?? new List(); + return await Try.ItAsync(async () => + await source + .WithHeader("User-Agent", "Other") + .GetJsonAsync>()) + ?? new List(); } public bool IsKindRetrievable(BrewKind kind) diff --git a/SHM/FormGetHomebrew.cs b/SHM/FormGetHomebrew.cs index 4805c0b..ba69b7b 100644 --- a/SHM/FormGetHomebrew.cs +++ b/SHM/FormGetHomebrew.cs @@ -188,6 +188,7 @@ private void LoadDatabase_sync(string path, Action> result)// bool ad try { WebClient wc = new WebClient(); + wc.Headers.Add("User-Agent: Other"); string content = wc.DownloadString(new Uri(path)); wc.Dispose(); content = Encoding.UTF8.GetString(Encoding.Default.GetBytes(content));