public async Task <dynamic> PostJson(string path, string content, CancellationToken cancellationToken = default) { var response = await HttpClient.PostAsync(path, new JsonContent(content), cancellationToken); await EnsureResponceSuccessfull(response); using (var stream = await response.Content.ReadAsStreamAsync()) { return(await DJson.ParseAsync(stream, DefaultOptions, cancellationToken)); } }
/// <summary> /// Send a GET request to the specified Uri and return the response body as a dynamic JSON. /// </summary> /// <param name="client">Http client.</param> /// <param name="requestUri">The Uri the request is sent to.</param> /// <param name="options">Options to control the behavior during reading.</param> /// <param name="cancellationToken">A token that may be used to cansel the read operation.</param> /// <returns></returns> public static async Task <dynamic> GetJsonAsync( this HttpClient client, Uri requestUri, JsonSerializerOptions options = null, CancellationToken cancellationToken = default) { using (var stream = await client.GetStreamAsync(requestUri)) { return(await DJson.ParseAsync(stream, options, cancellationToken)); } }