mirror of
https://github.com/Sonarr/Sonarr
synced 2026-01-16 20:41:31 +01:00
Added UserAgent to DownloadString and DownloadFile
Fixed: Downloading nzbs from sites that require specific information in the request header
This commit is contained in:
parent
d7c5f21cc6
commit
fd89435df8
1 changed files with 5 additions and 1 deletions
|
|
@ -12,10 +12,12 @@ public class HttpProvider
|
|||
{
|
||||
private readonly EnvironmentProvider _environmentProvider;
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly string _userAgent;
|
||||
|
||||
public HttpProvider(EnvironmentProvider environmentProvider)
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
_userAgent = String.Format("NzbDrone {0}", _environmentProvider.Version);
|
||||
}
|
||||
|
||||
public HttpProvider()
|
||||
|
|
@ -37,6 +39,7 @@ public virtual string DownloadString(string address, ICredentials identity)
|
|||
try
|
||||
{
|
||||
var client = new WebClient { Credentials = identity };
|
||||
client.Headers.Add(HttpRequestHeader.UserAgent, _userAgent);
|
||||
return client.DownloadString(address);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -49,7 +52,7 @@ public virtual string DownloadString(string address, ICredentials identity)
|
|||
public virtual Stream DownloadStream(string url, NetworkCredential credential)
|
||||
{
|
||||
var request = (HttpWebRequest)WebRequest.Create(url);
|
||||
request.UserAgent = String.Format("NzbDrone {0}", _environmentProvider.Version);
|
||||
request.UserAgent = _userAgent;
|
||||
|
||||
request.Credentials = credential;
|
||||
var response = request.GetResponse();
|
||||
|
|
@ -71,6 +74,7 @@ public virtual void DownloadFile(string url, string fileName)
|
|||
|
||||
var stopWatch = Stopwatch.StartNew();
|
||||
var webClient = new WebClient();
|
||||
webClient.Headers.Add(HttpRequestHeader.UserAgent, _userAgent);
|
||||
webClient.DownloadFile(url, fileName);
|
||||
stopWatch.Stop();
|
||||
logger.Trace("Downloading Completed. took {0:0}s", stopWatch.Elapsed.Seconds);
|
||||
|
|
|
|||
Loading…
Reference in a new issue