HttpClientManager.cs 25 KB

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