Providing User Agent for Http.Download method (#874)

This commit is contained in:
Tobias Tschinkowitz
2016-07-27 15:25:16 +02:00
committed by bao-qian
parent 04275cd702
commit 11b6946e00

View File

@@ -9,6 +9,8 @@ namespace Wox.Infrastructure.Http
{
public static class Http
{
private const string UserAgent = @"Mozilla/5.0 (Trident/7.0; rv:11.0) like Gecko";
public static HttpProxy Proxy { private get; set; }
public static IWebProxy WebProxy()
{
@@ -38,6 +40,7 @@ namespace Wox.Infrastructure.Http
public static void Download([NotNull] string url, [NotNull] string filePath)
{
var client = new WebClient { Proxy = WebProxy() };
client.Headers.Add("user-agent", UserAgent);
client.DownloadFile(url, filePath);
}
@@ -49,7 +52,7 @@ namespace Wox.Infrastructure.Http
request.Method = "GET";
request.Timeout = 10 * 1000;
request.Proxy = WebProxy();
request.UserAgent = @"Mozilla/5.0 (Trident/7.0; rv:11.0) like Gecko";
request.UserAgent = UserAgent;
var response = await request.GetResponseAsync() as HttpWebResponse;
if (response != null)
{