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

@ -21,8 +21,8 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
try
{
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));
var root = json.RootElement.GetProperty("AS");
@ -31,16 +31,16 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
return new List<string>();
return root.GetProperty("Results")
.EnumerateArray()
.SelectMany(r => r.GetProperty("Suggests")
.EnumerateArray()
.Select(s => s.GetProperty("Txt").GetString()))
.ToList();
.EnumerateArray()
.SelectMany(r => r.GetProperty("Suggests")
.EnumerateArray()
.Select(s => s.GetProperty("Txt").GetString()))
.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);
return null;
@ -49,7 +49,7 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
{
Log.Exception("|Bing.Suggestions|can't parse suggestions", e);
return new List<string>();
}
}
}
public override string ToString()