2011-03-07 06:33:59 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Net;
|
2011-04-05 05:30:13 +00:00
|
|
|
|
using System.Xml;
|
2011-03-07 06:33:59 +00:00
|
|
|
|
using NLog;
|
2010-09-28 03:40:01 +00:00
|
|
|
|
|
2011-04-04 03:50:12 +00:00
|
|
|
|
namespace NzbDrone.Core.Providers.Core
|
2010-09-28 03:40:01 +00:00
|
|
|
|
{
|
2011-04-07 02:25:52 +00:00
|
|
|
|
public class HttpProvider
|
2010-09-28 03:40:01 +00:00
|
|
|
|
{
|
2011-03-07 06:33:59 +00:00
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2011-04-07 02:25:52 +00:00
|
|
|
|
public virtual string DownloadString(string request)
|
2010-09-28 03:40:01 +00:00
|
|
|
|
{
|
2011-03-07 06:33:59 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return new WebClient().DownloadString(request);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Warn("Failed to get response from: {0}", request);
|
|
|
|
|
Logger.TraceException(ex.Message, ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return String.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-07 02:25:52 +00:00
|
|
|
|
public virtual string DownloadString(string request, string username, string password)
|
2011-03-07 06:33:59 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var webClient = new WebClient();
|
|
|
|
|
webClient.Credentials = new NetworkCredential(username, password);
|
|
|
|
|
return webClient.DownloadString(request);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Warn("Failed to get response from: {0}", request);
|
|
|
|
|
Logger.TraceException(ex.Message, ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return String.Empty;
|
2010-09-28 03:40:01 +00:00
|
|
|
|
}
|
2011-03-22 03:51:03 +00:00
|
|
|
|
|
2011-04-07 02:25:52 +00:00
|
|
|
|
public virtual void DownloadFile(string request, string filename)
|
2011-03-22 03:51:03 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var webClient = new WebClient();
|
|
|
|
|
webClient.DownloadFile(request, filename);
|
2011-04-05 05:30:13 +00:00
|
|
|
|
|
2011-03-22 03:51:03 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Warn("Failed to get response from: {0}", request);
|
|
|
|
|
Logger.TraceException(ex.Message, ex);
|
2011-04-05 05:30:13 +00:00
|
|
|
|
throw;
|
2011-03-22 03:51:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-05 05:30:13 +00:00
|
|
|
|
|
2011-03-22 03:51:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-07 02:25:52 +00:00
|
|
|
|
public virtual void DownloadFile(string request, string filename, string username, string password)
|
2011-03-22 03:51:03 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var webClient = new WebClient();
|
|
|
|
|
webClient.Credentials = new NetworkCredential(username, password);
|
|
|
|
|
webClient.DownloadFile(request, filename);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Warn("Failed to get response from: {0}", request);
|
|
|
|
|
Logger.TraceException(ex.Message, ex);
|
2011-04-05 05:30:13 +00:00
|
|
|
|
throw;
|
2011-03-22 03:51:03 +00:00
|
|
|
|
}
|
2011-04-05 05:30:13 +00:00
|
|
|
|
}
|
2011-03-22 03:51:03 +00:00
|
|
|
|
|
2011-04-07 02:25:52 +00:00
|
|
|
|
public virtual XmlReader DownloadXml(string url)
|
2011-04-05 05:30:13 +00:00
|
|
|
|
{
|
|
|
|
|
return XmlReader.Create(url);
|
2011-03-22 03:51:03 +00:00
|
|
|
|
}
|
2010-09-28 03:40:01 +00:00
|
|
|
|
}
|
2010-09-28 05:58:49 +00:00
|
|
|
|
}
|