async Task <string> UploadTorrent(byte[] content) { HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Put, "torrents/addTorrent") { Content = new ByteArrayContent(content) }; var resp = await _httpClient.SendAsync(message); try { resp.EnsureSuccessStatusCode(); } catch (HttpRequestException ex) { _logger.LogError(ex, "Torrent upload failed, check your API key or your subscruption"); _logger.LogInformation(await resp.Content.ReadAsStringAsync()); //Implement logging depends on reqponse code //HTTP Status Code Reason //400 Bad Request(see error message) //401 Bad token(expired, invalid) //403 Permission denied(account locked, not premium) //503 Service unavailable(see error message) throw; } TorrentAdd result = TorrentAdd.FromJson(await resp.Content.ReadAsStringAsync()); return(result.Id); }
public static string ToJson(this TorrentAdd self) => JsonConvert.SerializeObject(self, Converter.Settings);