2014-03-13 22:31:44 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
|
|
|
|
namespace Wox.Plugin.PluginManagement
|
|
|
|
|
{
|
|
|
|
|
public class HttpRequest
|
|
|
|
|
{
|
|
|
|
|
private static readonly string DefaultUserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
|
|
|
|
|
|
2014-07-18 20:00:55 +08:00
|
|
|
|
public static HttpWebResponse CreateGetHttpResponse(string url,IHttpProxy proxy)
|
2014-03-13 22:31:44 +08:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(url))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("url");
|
|
|
|
|
}
|
|
|
|
|
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
|
2014-07-18 20:00:55 +08:00
|
|
|
|
if (proxy != null && proxy.Enabled && !string.IsNullOrEmpty(proxy.Server))
|
2014-03-13 22:31:44 +08:00
|
|
|
|
{
|
2014-07-18 20:00:55 +08:00
|
|
|
|
if (string.IsNullOrEmpty(proxy.UserName) || string.IsNullOrEmpty(proxy.Password))
|
2014-03-13 22:31:44 +08:00
|
|
|
|
{
|
2014-07-18 20:00:55 +08:00
|
|
|
|
request.Proxy = new WebProxy(proxy.Server, proxy.Port);
|
2014-03-13 22:31:44 +08:00
|
|
|
|
}
|
2014-07-18 20:00:55 +08:00
|
|
|
|
else
|
2014-03-13 22:31:44 +08:00
|
|
|
|
{
|
2014-07-18 20:00:55 +08:00
|
|
|
|
request.Proxy = new WebProxy(proxy.Server, proxy.Port);
|
|
|
|
|
request.Proxy.Credentials = new NetworkCredential(proxy.UserName, proxy.Password);
|
2014-03-13 22:31:44 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-18 20:00:55 +08:00
|
|
|
|
request.Method = "GET";
|
|
|
|
|
request.UserAgent = DefaultUserAgent;
|
2014-03-13 22:31:44 +08:00
|
|
|
|
return request.GetResponse() as HttpWebResponse;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|