2011-03-07 07:33:59 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using NLog;
|
2010-09-28 05:40:01 +02:00
|
|
|
|
|
2010-09-28 06:25:41 +02:00
|
|
|
|
namespace NzbDrone.Core.Providers
|
2010-09-28 05:40:01 +02:00
|
|
|
|
{
|
2010-09-28 07:58:49 +02:00
|
|
|
|
internal class HttpProvider : IHttpProvider
|
2010-09-28 05:40:01 +02:00
|
|
|
|
{
|
2011-03-07 07:33:59 +01:00
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2010-09-28 07:01:54 +02:00
|
|
|
|
public string DownloadString(string request)
|
2010-09-28 05:40:01 +02:00
|
|
|
|
{
|
2011-03-07 07:33:59 +01: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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string DownloadString(string request, string username, string password)
|
|
|
|
|
{
|
|
|
|
|
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 05:40:01 +02:00
|
|
|
|
}
|
2011-03-22 04:51:03 +01:00
|
|
|
|
|
|
|
|
|
public bool DownloadFile(string request, string filename)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var webClient = new WebClient();
|
|
|
|
|
webClient.DownloadFile(request, filename);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Warn("Failed to get response from: {0}", request);
|
|
|
|
|
Logger.TraceException(ex.Message, ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool DownloadFile(string request, string filename, string username, string password)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var webClient = new WebClient();
|
|
|
|
|
webClient.Credentials = new NetworkCredential(username, password);
|
|
|
|
|
webClient.DownloadFile(request, filename);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Warn("Failed to get response from: {0}", request);
|
|
|
|
|
Logger.TraceException(ex.Message, ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-09-28 05:40:01 +02:00
|
|
|
|
}
|
2010-09-28 07:58:49 +02:00
|
|
|
|
}
|