diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-05-06 22:28:19 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-05-06 22:28:19 -0400 |
| commit | 0d025f7fb620bf2a24ca9aa4e5994f132e02e7c0 (patch) | |
| tree | 76137f5f868ed81725d29bbdc6ac0e3b57c304d8 /OpenSubtitlesHandler/Utilities.cs | |
| parent | e1dd361c7bf05af49d9210ab679e85fa00870990 (diff) | |
beginning remote subtitle downloading
Diffstat (limited to 'OpenSubtitlesHandler/Utilities.cs')
| -rw-r--r-- | OpenSubtitlesHandler/Utilities.cs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/OpenSubtitlesHandler/Utilities.cs b/OpenSubtitlesHandler/Utilities.cs index 5c72f4fde..7f0f93009 100644 --- a/OpenSubtitlesHandler/Utilities.cs +++ b/OpenSubtitlesHandler/Utilities.cs @@ -24,6 +24,7 @@ using System.IO; using System.IO.Compression; using System.Net; using System.Security.Cryptography; +using System.Threading; using System.Threading.Tasks; using MediaBrowser.Common.Net; @@ -161,7 +162,7 @@ namespace OpenSubtitlesHandler /// <returns>Response of the server or stream of error message as string started with 'ERROR:' keyword.</returns> public static Stream SendRequest(byte[] request, string userAgent) { - return SendRequestAsync(request, userAgent).Result; + return SendRequestAsync(request, userAgent, CancellationToken.None).Result; //HttpWebRequest req = (HttpWebRequest)WebRequest.Create(XML_RPC_SERVER); //req.ContentType = "text/xml"; @@ -190,16 +191,27 @@ namespace OpenSubtitlesHandler //} } - public static async Task<Stream> SendRequestAsync(byte[] request, string userAgent) + public static async Task<Stream> SendRequestAsync(byte[] request, string userAgent, CancellationToken cancellationToken) { var options = new HttpRequestOptions { RequestContentBytes = request, RequestContentType = "text/xml", - UserAgent = "xmlrpc-epi-php/0.2 (PHP)", - Url = XML_RPC_SERVER + UserAgent = userAgent, + Host = "api.opensubtitles.org:80", + Url = XML_RPC_SERVER, + + // Response parsing will fail with this enabled + EnableHttpCompression = false, + + CancellationToken = cancellationToken }; + if (string.IsNullOrEmpty(options.UserAgent)) + { + options.UserAgent = "xmlrpc-epi-php/0.2 (PHP)"; + } + var result = await HttpClient.Post(options).ConfigureAwait(false); return result.Content; |
