mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
use unified http method for plugin installation + add more exceptions
#573 #610
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
@@ -18,7 +19,20 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
|
||||
public override async Task<List<string>> GetSuggestions(string query)
|
||||
{
|
||||
var result = await HttpRequest.Get("http://suggestion.baidu.com/su?json=1&wd=" + Uri.EscapeUriString(query), Proxy, "GB2312");
|
||||
string result;
|
||||
|
||||
try
|
||||
{
|
||||
const string api = "http://suggestion.baidu.com/su?json=1&wd=";
|
||||
result = await Http.Get(api + Uri.EscapeUriString(query), Proxy, "GB2312");
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
Log.Warn("Can't get suggestion from baidu");
|
||||
Log.Error(e);
|
||||
return new List<string>(); ;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(result)) return new List<string>();
|
||||
|
||||
Match match = reg.Match(result);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
@@ -14,7 +15,18 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
public override string Domain { get; set; } = "www.google.com";
|
||||
public override async Task<List<string>> GetSuggestions(string query)
|
||||
{
|
||||
var result = await HttpRequest.Get("https://www.google.com/complete/search?output=chrome&q=" + Uri.EscapeUriString(query), Proxy);
|
||||
string result;
|
||||
try
|
||||
{
|
||||
const string api = "https://www.google.com/complete/search?output=chrome&q=";
|
||||
result = await Http.Get(api + Uri.EscapeUriString(query), Proxy);
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
Log.Warn("Can't get suggestion from google");
|
||||
Log.Error(e);
|
||||
return new List<string>(); ;
|
||||
}
|
||||
if (string.IsNullOrEmpty(result)) return new List<string>();
|
||||
JContainer json;
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user