private static async Task <HttpResponseMessage> PutFileAsync(Uri url, byte[] file) { var request = new FlurlRequest(url); var response = await request.SendAsync(HttpMethod.Put, new ByteArrayContent(file)); return(response); }
private static async Task <byte[]> GetFileAsync(Uri url) { var request = new FlurlRequest(url); var response = await request.SendAsync(HttpMethod.Get); return(await response.Content.ReadAsByteArrayAsync()); }
/// <summary> /// request url that specified by yourself with post method. /// according the package Flurl.Http.GeneratedExtensions to rewrite it in order to debug, develop. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="url"></param> /// <param name="data"></param> /// <param name="cancellationToken"></param> /// <param name="completionOption"></param> /// <returns></returns> public static Task <T> PostJsonAsync <T>(this Flurl.Url url, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { var request = new FlurlRequest(url); CapturedJsonContent content = new CapturedJsonContent(request.Settings.JsonSerializer.Serialize(data)); var response = request.SendAsync(HttpMethod.Post, content, cancellationToken, completionOption); var result = response.ReceiveJson <T>(); return(result); }
public async Task <IEnumerable <Transaction> > GetTransactions(string address) { var url = _nodeAddress.AppendPathSegments("api", "transactions", address); var request = new FlurlRequest(url); var response = await request.SendAsync(HttpMethod.Get); return(await Task.FromResult(response).ReceiveJson <IEnumerable <Transaction> >()); }
public async Task <Block> GetBlock(int id) { var url = _nodeAddress.AppendPathSegments("api", "block", id.ToString()); var request = new FlurlRequest(url); var response = await request.SendAsync(HttpMethod.Get); if (response.StatusCode == HttpStatusCode.NotFound) { return(null); } return(await Task.FromResult(response).ReceiveJson <Block>()); }
public async Task <Transaction> GetTransaction(string hash) { var url = _nodeAddress.AppendPathSegments("api", "transactions"); url.QueryParams.Add("transactionHash", hash); var request = new FlurlRequest(url); var response = await request.SendAsync(HttpMethod.Get); if (response.StatusCode == HttpStatusCode.NotFound) { return(null); } return(await Task.FromResult(response).ReceiveJson <Transaction>()); }
public static async Task <byte[]> GetDataAsync(this string url) { if (string.IsNullOrWhiteSpace(url)) { return(new byte[] { }); } var request = new FlurlRequest(url); using (var response = await request.SendAsync(HttpMethod.Get)) using (var httpStream = await response.Content.ReadAsStreamAsync()) using (var memStream = new MemoryStream()) { await httpStream.CopyToAsync(memStream); return(memStream.ToArray()); } }