private async Task <HttpResponseMessage> DownloadFile(WsFile file, CancellationToken cancellationToken) { FileLinkResult fileLinkResult = await PostFormDataWithNotFoundAndLoginRetry(file, () => { FormUrlEncodedContent formContent = CreateFormContent(new[] { new KeyValuePair <string, string>("ident", file.Ident), new KeyValuePair <string, string>("password", ""), new KeyValuePair <string, string>("download_type", "file_download"), new KeyValuePair <string, string>("device_uuid", _deviceUuid.ToString()), new KeyValuePair <string, string>("device_res_x", "1920"), new KeyValuePair <string, string>("device_res_x", "1080"), new KeyValuePair <string, string>("force_https", "1") }); return(_httpClient.PostFormData <FileLinkResult>(API_FILE_LINK_URI, formContent, cancellationToken)); }); return(await _httpClient.GetData(new Uri(fileLinkResult.Link), cancellationToken)); }
private async Task <byte[]> GetJpgData(WsHttpClient httpClient) { if (_disposed || string.IsNullOrWhiteSpace(Url)) { return(JpgData.Result); } try { using (_cts = new CancellationTokenSource()) using (HttpResponseMessage response = await httpClient.GetData(new Uri(Url), _cts.Token)) { return(await response.Content.ReadAsByteArrayAsync()); } } finally { _cts = null; } }