Adjust Bing Code a bit due to http change

This commit is contained in:
Hongtao Zhang 2022-10-12 23:32:02 -05:00
parent 3708489886
commit 191c6af38e

View file

@ -22,7 +22,7 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
{ {
const string api = "https://api.bing.com/qsonhs.aspx?q="; const string api = "https://api.bing.com/qsonhs.aspx?q=";
using var resultStream = await Http.GetStreamAsync(api + Uri.EscapeDataString(query), token).ConfigureAwait(false); await using var resultStream = await Http.GetStreamAsync(api + Uri.EscapeDataString(query), HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(false);
using var json = (await JsonDocument.ParseAsync(resultStream, cancellationToken: token)); using var json = (await JsonDocument.ParseAsync(resultStream, cancellationToken: token));
var root = json.RootElement.GetProperty("AS"); var root = json.RootElement.GetProperty("AS");
@ -31,16 +31,16 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
return new List<string>(); return new List<string>();
return root.GetProperty("Results") return root.GetProperty("Results")
.EnumerateArray() .EnumerateArray()
.SelectMany(r => r.GetProperty("Suggests") .SelectMany(r => r.GetProperty("Suggests")
.EnumerateArray() .EnumerateArray()
.Select(s => s.GetProperty("Txt").GetString())) .Select(s => s.GetProperty("Txt").GetString()))
.ToList(); .ToList();
} }
catch (Exception e) when (e is HttpRequestException or {InnerException: TimeoutException}) catch (Exception e) when (e is HttpRequestException or { InnerException: TimeoutException })
{ {
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e); Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
return null; return null;