HttpClientManager.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. using MediaBrowser.Common.Configuration;
  2. using MediaBrowser.Common.IO;
  3. using MediaBrowser.Common.Net;
  4. using MediaBrowser.Model.Logging;
  5. using MediaBrowser.Model.Net;
  6. using System;
  7. using System.Collections.Concurrent;
  8. using System.Collections.Generic;
  9. using System.Collections.Specialized;
  10. using System.Globalization;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Net;
  14. using System.Net.Cache;
  15. using System.Net.Http;
  16. using System.Reflection;
  17. using System.Text;
  18. using System.Threading;
  19. using System.Threading.Tasks;
  20. namespace MediaBrowser.Common.Implementations.HttpClientManager
  21. {
  22. /// <summary>
  23. /// Class HttpClientManager
  24. /// </summary>
  25. public class HttpClientManager : IHttpClient
  26. {
  27. /// <summary>
  28. /// When one request to a host times out, we'll ban all other requests for this period of time, to prevent scans from stalling
  29. /// </summary>
  30. private const int TimeoutSeconds = 30;
  31. /// <summary>
  32. /// The _logger
  33. /// </summary>
  34. private readonly ILogger _logger;
  35. /// <summary>
  36. /// The _app paths
  37. /// </summary>
  38. private readonly IApplicationPaths _appPaths;
  39. private readonly IFileSystem _fileSystem;
  40. private readonly IConfigurationManager _config;
  41. /// <summary>
  42. /// Initializes a new instance of the <see cref="HttpClientManager" /> class.
  43. /// </summary>
  44. /// <param name="appPaths">The app paths.</param>
  45. /// <param name="logger">The logger.</param>
  46. /// <param name="fileSystem">The file system.</param>
  47. /// <exception cref="System.ArgumentNullException">appPaths
  48. /// or
  49. /// logger</exception>
  50. public HttpClientManager(IApplicationPaths appPaths, ILogger logger, IFileSystem fileSystem, IConfigurationManager config)
  51. {
  52. if (appPaths == null)
  53. {
  54. throw new ArgumentNullException("appPaths");
  55. }
  56. if (logger == null)
  57. {
  58. throw new ArgumentNullException("logger");
  59. }
  60. _logger = logger;
  61. _fileSystem = fileSystem;
  62. _config = config;
  63. _appPaths = appPaths;
  64. // http://stackoverflow.com/questions/566437/http-post-returns-the-error-417-expectation-failed-c
  65. ServicePointManager.Expect100Continue = false;
  66. }
  67. /// <summary>
  68. /// Holds a dictionary of http clients by host. Use GetHttpClient(host) to retrieve or create a client for web requests.
  69. /// DON'T dispose it after use.
  70. /// </summary>
  71. /// <value>The HTTP clients.</value>
  72. private readonly ConcurrentDictionary<string, HttpClientInfo> _httpClients = new ConcurrentDictionary<string, HttpClientInfo>();
  73. /// <summary>
  74. /// Gets
  75. /// </summary>
  76. /// <param name="host">The host.</param>
  77. /// <param name="enableHttpCompression">if set to <c>true</c> [enable HTTP compression].</param>
  78. /// <returns>HttpClient.</returns>
  79. /// <exception cref="System.ArgumentNullException">host</exception>
  80. private HttpClientInfo GetHttpClient(string host, bool enableHttpCompression)
  81. {
  82. if (string.IsNullOrEmpty(host))
  83. {
  84. throw new ArgumentNullException("host");
  85. }
  86. HttpClientInfo client;
  87. var key = host + enableHttpCompression;
  88. if (!_httpClients.TryGetValue(key, out client))
  89. {
  90. client = new HttpClientInfo();
  91. _httpClients.TryAdd(key, client);
  92. }
  93. return client;
  94. }
  95. private PropertyInfo _httpBehaviorPropertyInfo;
  96. private WebRequest GetRequest(HttpRequestOptions options, string method, bool enableHttpCompression)
  97. {
  98. var request = (HttpWebRequest)WebRequest.Create(options.Url);
  99. AddRequestHeaders(request, options);
  100. request.AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None;
  101. request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);
  102. request.KeepAlive = options.EnableKeepAlive;
  103. request.Method = method;
  104. request.Pipelined = true;
  105. request.Timeout = 20000;
  106. if (!string.IsNullOrEmpty(options.Host))
  107. {
  108. request.Host = options.Host;
  109. }
  110. #if !__MonoCS__
  111. if (options.EnableKeepAlive)
  112. {
  113. // This is a hack to prevent KeepAlive from getting disabled internally by the HttpWebRequest
  114. // May need to remove this for mono
  115. var sp = request.ServicePoint;
  116. if (_httpBehaviorPropertyInfo == null)
  117. {
  118. _httpBehaviorPropertyInfo = sp.GetType().GetProperty("HttpBehaviour", BindingFlags.Instance | BindingFlags.NonPublic);
  119. }
  120. _httpBehaviorPropertyInfo.SetValue(sp, (byte)0, null);
  121. }
  122. #endif
  123. return request;
  124. }
  125. private void AddRequestHeaders(HttpWebRequest request, HttpRequestOptions options)
  126. {
  127. foreach (var header in options.RequestHeaders.ToList())
  128. {
  129. if (string.Equals(header.Key, "Accept", StringComparison.OrdinalIgnoreCase))
  130. {
  131. request.Accept = header.Value;
  132. }
  133. else if (string.Equals(header.Key, "User-Agent", StringComparison.OrdinalIgnoreCase))
  134. {
  135. request.UserAgent = header.Value;
  136. }
  137. else
  138. {
  139. request.Headers.Set(header.Key, header.Value);
  140. }
  141. }
  142. }
  143. /// <summary>
  144. /// Gets the response internal.
  145. /// </summary>
  146. /// <param name="options">The options.</param>
  147. /// <returns>Task{HttpResponseInfo}.</returns>
  148. public Task<HttpResponseInfo> GetResponse(HttpRequestOptions options)
  149. {
  150. return SendAsync(options, "GET");
  151. }
  152. /// <summary>
  153. /// Performs a GET request and returns the resulting stream
  154. /// </summary>
  155. /// <param name="options">The options.</param>
  156. /// <returns>Task{Stream}.</returns>
  157. public async Task<Stream> Get(HttpRequestOptions options)
  158. {
  159. var response = await GetResponse(options).ConfigureAwait(false);
  160. return response.Content;
  161. }
  162. /// <summary>
  163. /// Performs a GET request and returns the resulting stream
  164. /// </summary>
  165. /// <param name="url">The URL.</param>
  166. /// <param name="resourcePool">The resource pool.</param>
  167. /// <param name="cancellationToken">The cancellation token.</param>
  168. /// <returns>Task{Stream}.</returns>
  169. public Task<Stream> Get(string url, SemaphoreSlim resourcePool, CancellationToken cancellationToken)
  170. {
  171. return Get(new HttpRequestOptions
  172. {
  173. Url = url,
  174. ResourcePool = resourcePool,
  175. CancellationToken = cancellationToken,
  176. });
  177. }
  178. /// <summary>
  179. /// Gets the specified URL.
  180. /// </summary>
  181. /// <param name="url">The URL.</param>
  182. /// <param name="cancellationToken">The cancellation token.</param>
  183. /// <returns>Task{Stream}.</returns>
  184. public Task<Stream> Get(string url, CancellationToken cancellationToken)
  185. {
  186. return Get(url, null, cancellationToken);
  187. }
  188. /// <summary>
  189. /// send as an asynchronous operation.
  190. /// </summary>
  191. /// <param name="options">The options.</param>
  192. /// <param name="httpMethod">The HTTP method.</param>
  193. /// <returns>Task{HttpResponseInfo}.</returns>
  194. /// <exception cref="HttpException">
  195. /// </exception>
  196. public async Task<HttpResponseInfo> SendAsync(HttpRequestOptions options, string httpMethod)
  197. {
  198. ValidateParams(options);
  199. options.CancellationToken.ThrowIfCancellationRequested();
  200. var client = GetHttpClient(GetHostFromUrl(options.Url), options.EnableHttpCompression);
  201. if ((DateTime.UtcNow - client.LastTimeout).TotalSeconds < TimeoutSeconds)
  202. {
  203. throw new HttpException(string.Format("Cancelling connection to {0} due to a previous timeout.", options.Url)) { IsTimedOut = true };
  204. }
  205. var httpWebRequest = GetRequest(options, httpMethod, options.EnableHttpCompression);
  206. if (options.RequestContentBytes != null ||
  207. !string.IsNullOrEmpty(options.RequestContent) ||
  208. string.Equals(httpMethod, "post", StringComparison.OrdinalIgnoreCase))
  209. {
  210. var bytes = options.RequestContentBytes ??
  211. Encoding.UTF8.GetBytes(options.RequestContent ?? string.Empty);
  212. httpWebRequest.ContentType = options.RequestContentType ?? "application/x-www-form-urlencoded";
  213. httpWebRequest.ContentLength = bytes.Length;
  214. httpWebRequest.GetRequestStream().Write(bytes, 0, bytes.Length);
  215. }
  216. if (options.ResourcePool != null)
  217. {
  218. await options.ResourcePool.WaitAsync(options.CancellationToken).ConfigureAwait(false);
  219. }
  220. if ((DateTime.UtcNow - client.LastTimeout).TotalSeconds < TimeoutSeconds)
  221. {
  222. if (options.ResourcePool != null)
  223. {
  224. options.ResourcePool.Release();
  225. }
  226. throw new HttpException(string.Format("Connection to {0} timed out", options.Url)) { IsTimedOut = true };
  227. }
  228. if (options.LogRequest)
  229. {
  230. _logger.Info("HttpClientManager {0}: {1}", httpMethod.ToUpper(), options.Url);
  231. }
  232. try
  233. {
  234. options.CancellationToken.ThrowIfCancellationRequested();
  235. if (!options.BufferContent)
  236. {
  237. var response = await httpWebRequest.GetResponseAsync().ConfigureAwait(false);
  238. var httpResponse = (HttpWebResponse)response;
  239. EnsureSuccessStatusCode(httpResponse, options);
  240. options.CancellationToken.ThrowIfCancellationRequested();
  241. return GetResponseInfo(httpResponse, httpResponse.GetResponseStream(), GetContentLength(httpResponse));
  242. }
  243. using (var response = await httpWebRequest.GetResponseAsync().ConfigureAwait(false))
  244. {
  245. var httpResponse = (HttpWebResponse)response;
  246. EnsureSuccessStatusCode(httpResponse, options);
  247. options.CancellationToken.ThrowIfCancellationRequested();
  248. using (var stream = httpResponse.GetResponseStream())
  249. {
  250. var memoryStream = new MemoryStream();
  251. await stream.CopyToAsync(memoryStream).ConfigureAwait(false);
  252. memoryStream.Position = 0;
  253. return GetResponseInfo(httpResponse, memoryStream, memoryStream.Length);
  254. }
  255. }
  256. }
  257. catch (OperationCanceledException ex)
  258. {
  259. var exception = GetCancellationException(options.Url, options.CancellationToken, ex);
  260. var httpException = exception as HttpException;
  261. if (httpException != null && httpException.IsTimedOut)
  262. {
  263. client.LastTimeout = DateTime.UtcNow;
  264. }
  265. throw exception;
  266. }
  267. catch (HttpRequestException ex)
  268. {
  269. _logger.ErrorException("Error getting response from " + options.Url, ex);
  270. throw new HttpException(ex.Message, ex);
  271. }
  272. catch (WebException ex)
  273. {
  274. throw GetException(ex, options);
  275. }
  276. catch (Exception ex)
  277. {
  278. _logger.ErrorException("Error getting response from " + options.Url, ex);
  279. throw;
  280. }
  281. finally
  282. {
  283. if (options.ResourcePool != null)
  284. {
  285. options.ResourcePool.Release();
  286. }
  287. }
  288. }
  289. /// <summary>
  290. /// Gets the exception.
  291. /// </summary>
  292. /// <param name="ex">The ex.</param>
  293. /// <param name="options">The options.</param>
  294. /// <returns>HttpException.</returns>
  295. private HttpException GetException(WebException ex, HttpRequestOptions options)
  296. {
  297. _logger.ErrorException("Error getting response from " + options.Url, ex);
  298. return new HttpException(ex.Message, ex);
  299. }
  300. private HttpResponseInfo GetResponseInfo(HttpWebResponse httpResponse, Stream content, long? contentLength)
  301. {
  302. return new HttpResponseInfo
  303. {
  304. Content = content,
  305. StatusCode = httpResponse.StatusCode,
  306. ContentType = httpResponse.ContentType,
  307. Headers = new NameValueCollection(httpResponse.Headers),
  308. ContentLength = contentLength
  309. };
  310. }
  311. private HttpResponseInfo GetResponseInfo(HttpWebResponse httpResponse, string tempFile, long? contentLength)
  312. {
  313. return new HttpResponseInfo
  314. {
  315. TempFilePath = tempFile,
  316. StatusCode = httpResponse.StatusCode,
  317. ContentType = httpResponse.ContentType,
  318. Headers = httpResponse.Headers,
  319. ContentLength = contentLength
  320. };
  321. }
  322. public Task<HttpResponseInfo> Post(HttpRequestOptions options)
  323. {
  324. return SendAsync(options, "POST");
  325. }
  326. /// <summary>
  327. /// Performs a POST request
  328. /// </summary>
  329. /// <param name="options">The options.</param>
  330. /// <param name="postData">Params to add to the POST data.</param>
  331. /// <returns>stream on success, null on failure</returns>
  332. public async Task<Stream> Post(HttpRequestOptions options, Dictionary<string, string> postData)
  333. {
  334. var strings = postData.Keys.Select(key => string.Format("{0}={1}", key, postData[key]));
  335. var postContent = string.Join("&", strings.ToArray());
  336. options.RequestContent = postContent;
  337. options.RequestContentType = "application/x-www-form-urlencoded";
  338. var response = await Post(options).ConfigureAwait(false);
  339. return response.Content;
  340. }
  341. /// <summary>
  342. /// Performs a POST request
  343. /// </summary>
  344. /// <param name="url">The URL.</param>
  345. /// <param name="postData">Params to add to the POST data.</param>
  346. /// <param name="resourcePool">The resource pool.</param>
  347. /// <param name="cancellationToken">The cancellation token.</param>
  348. /// <returns>stream on success, null on failure</returns>
  349. public Task<Stream> Post(string url, Dictionary<string, string> postData, SemaphoreSlim resourcePool, CancellationToken cancellationToken)
  350. {
  351. return Post(new HttpRequestOptions
  352. {
  353. Url = url,
  354. ResourcePool = resourcePool,
  355. CancellationToken = cancellationToken
  356. }, postData);
  357. }
  358. /// <summary>
  359. /// Downloads the contents of a given url into a temporary location
  360. /// </summary>
  361. /// <param name="options">The options.</param>
  362. /// <returns>Task{System.String}.</returns>
  363. /// <exception cref="System.ArgumentNullException">progress</exception>
  364. public async Task<string> GetTempFile(HttpRequestOptions options)
  365. {
  366. var response = await GetTempFileResponse(options).ConfigureAwait(false);
  367. return response.TempFilePath;
  368. }
  369. public async Task<HttpResponseInfo> GetTempFileResponse(HttpRequestOptions options)
  370. {
  371. ValidateParams(options);
  372. Directory.CreateDirectory(_appPaths.TempDirectory);
  373. var tempFile = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + ".tmp");
  374. if (options.Progress == null)
  375. {
  376. throw new ArgumentNullException("progress");
  377. }
  378. options.CancellationToken.ThrowIfCancellationRequested();
  379. var httpWebRequest = GetRequest(options, "GET", options.EnableHttpCompression);
  380. if (options.ResourcePool != null)
  381. {
  382. await options.ResourcePool.WaitAsync(options.CancellationToken).ConfigureAwait(false);
  383. }
  384. options.Progress.Report(0);
  385. if (options.LogRequest)
  386. {
  387. _logger.Info("HttpClientManager.GetTempFileResponse url: {0}", options.Url);
  388. }
  389. try
  390. {
  391. options.CancellationToken.ThrowIfCancellationRequested();
  392. using (var response = await httpWebRequest.GetResponseAsync().ConfigureAwait(false))
  393. {
  394. var httpResponse = (HttpWebResponse)response;
  395. EnsureSuccessStatusCode(httpResponse, options);
  396. options.CancellationToken.ThrowIfCancellationRequested();
  397. var contentLength = GetContentLength(httpResponse);
  398. if (!contentLength.HasValue)
  399. {
  400. // We're not able to track progress
  401. using (var stream = httpResponse.GetResponseStream())
  402. {
  403. using (var fs = _fileSystem.GetFileStream(tempFile, FileMode.Create, FileAccess.Write, FileShare.Read, true))
  404. {
  405. await stream.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false);
  406. }
  407. }
  408. }
  409. else
  410. {
  411. using (var stream = ProgressStream.CreateReadProgressStream(httpResponse.GetResponseStream(), options.Progress.Report, contentLength.Value))
  412. {
  413. using (var fs = _fileSystem.GetFileStream(tempFile, FileMode.Create, FileAccess.Write, FileShare.Read, true))
  414. {
  415. await stream.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false);
  416. }
  417. }
  418. }
  419. options.Progress.Report(100);
  420. return GetResponseInfo(httpResponse, tempFile, contentLength);
  421. }
  422. }
  423. catch (OperationCanceledException ex)
  424. {
  425. throw GetTempFileException(ex, options, tempFile);
  426. }
  427. catch (HttpRequestException ex)
  428. {
  429. throw GetTempFileException(ex, options, tempFile);
  430. }
  431. catch (WebException ex)
  432. {
  433. throw GetTempFileException(ex, options, tempFile);
  434. }
  435. catch (Exception ex)
  436. {
  437. throw GetTempFileException(ex, options, tempFile);
  438. }
  439. finally
  440. {
  441. if (options.ResourcePool != null)
  442. {
  443. options.ResourcePool.Release();
  444. }
  445. }
  446. }
  447. private long? GetContentLength(HttpWebResponse response)
  448. {
  449. var length = response.ContentLength;
  450. if (length == 0)
  451. {
  452. return null;
  453. }
  454. return length;
  455. }
  456. protected static readonly CultureInfo UsCulture = new CultureInfo("en-US");
  457. /// <summary>
  458. /// Handles the temp file exception.
  459. /// </summary>
  460. /// <param name="ex">The ex.</param>
  461. /// <param name="options">The options.</param>
  462. /// <param name="tempFile">The temp file.</param>
  463. /// <returns>Task.</returns>
  464. /// <exception cref="HttpException"></exception>
  465. private Exception GetTempFileException(Exception ex, HttpRequestOptions options, string tempFile)
  466. {
  467. var operationCanceledException = ex as OperationCanceledException;
  468. if (operationCanceledException != null)
  469. {
  470. // Cleanup
  471. DeleteTempFile(tempFile);
  472. return GetCancellationException(options.Url, options.CancellationToken, operationCanceledException);
  473. }
  474. _logger.ErrorException("Error getting response from " + options.Url, ex);
  475. // Cleanup
  476. DeleteTempFile(tempFile);
  477. var httpRequestException = ex as HttpRequestException;
  478. if (httpRequestException != null)
  479. {
  480. return new HttpException(ex.Message, ex);
  481. }
  482. var webException = ex as WebException;
  483. if (webException != null)
  484. {
  485. throw GetException(webException, options);
  486. }
  487. return ex;
  488. }
  489. private void DeleteTempFile(string file)
  490. {
  491. try
  492. {
  493. File.Delete(file);
  494. }
  495. catch (IOException)
  496. {
  497. // Might not have been created at all. No need to worry.
  498. }
  499. }
  500. private void ValidateParams(HttpRequestOptions options)
  501. {
  502. if (string.IsNullOrEmpty(options.Url))
  503. {
  504. throw new ArgumentNullException("options");
  505. }
  506. }
  507. /// <summary>
  508. /// Gets the host from URL.
  509. /// </summary>
  510. /// <param name="url">The URL.</param>
  511. /// <returns>System.String.</returns>
  512. private string GetHostFromUrl(string url)
  513. {
  514. var start = url.IndexOf("://", StringComparison.OrdinalIgnoreCase) + 3;
  515. var len = url.IndexOf('/', start) - start;
  516. return url.Substring(start, len);
  517. }
  518. /// <summary>
  519. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  520. /// </summary>
  521. public void Dispose()
  522. {
  523. Dispose(true);
  524. GC.SuppressFinalize(this);
  525. }
  526. /// <summary>
  527. /// Releases unmanaged and - optionally - managed resources.
  528. /// </summary>
  529. /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  530. protected virtual void Dispose(bool dispose)
  531. {
  532. if (dispose)
  533. {
  534. _httpClients.Clear();
  535. }
  536. }
  537. /// <summary>
  538. /// Throws the cancellation exception.
  539. /// </summary>
  540. /// <param name="url">The URL.</param>
  541. /// <param name="cancellationToken">The cancellation token.</param>
  542. /// <param name="exception">The exception.</param>
  543. /// <returns>Exception.</returns>
  544. private Exception GetCancellationException(string url, CancellationToken cancellationToken, OperationCanceledException exception)
  545. {
  546. // If the HttpClient's timeout is reached, it will cancel the Task internally
  547. if (!cancellationToken.IsCancellationRequested)
  548. {
  549. var msg = string.Format("Connection to {0} timed out", url);
  550. _logger.Error(msg);
  551. // Throw an HttpException so that the caller doesn't think it was cancelled by user code
  552. return new HttpException(msg, exception) { IsTimedOut = true };
  553. }
  554. return exception;
  555. }
  556. private void EnsureSuccessStatusCode(HttpWebResponse response, HttpRequestOptions options)
  557. {
  558. var statusCode = response.StatusCode;
  559. var isSuccessful = statusCode >= HttpStatusCode.OK && statusCode <= (HttpStatusCode)299;
  560. if (!isSuccessful)
  561. {
  562. if (options.LogErrorResponseBody)
  563. {
  564. try
  565. {
  566. using (var stream = response.GetResponseStream())
  567. {
  568. if (stream != null)
  569. {
  570. using (var reader = new StreamReader(stream))
  571. {
  572. var msg = reader.ReadToEnd();
  573. _logger.Error(msg);
  574. }
  575. }
  576. }
  577. }
  578. catch
  579. {
  580. }
  581. }
  582. throw new HttpException(response.StatusDescription) { StatusCode = response.StatusCode };
  583. }
  584. }
  585. /// <summary>
  586. /// Posts the specified URL.
  587. /// </summary>
  588. /// <param name="url">The URL.</param>
  589. /// <param name="postData">The post data.</param>
  590. /// <param name="cancellationToken">The cancellation token.</param>
  591. /// <returns>Task{Stream}.</returns>
  592. public Task<Stream> Post(string url, Dictionary<string, string> postData, CancellationToken cancellationToken)
  593. {
  594. return Post(url, postData, null, cancellationToken);
  595. }
  596. }
  597. }