public static async Task Fetch(string url, FetchOptions options = null) { if (options==null) { options = new FetchOptions() { Body = null, Authorization = null, Method = "GET" }; } using(var request = new HttpRequestMessage(new HttpMethod(options.Method), url)) { if (options.Body != null) { request.Content = new StringContent(JsonSerializer.Serialize(options.Method), Encoding.UTF8, "application/json"); } if (options.Method==null)options.Method = "GET"; if (!string.IsNullOrEmpty(options.Authorization)) { request.Headers.Add("Authorization", $"Bearer {options.Authorization}"); //Returns correct token } var response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); //401 string json = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(json)) { return default; } try { return JsonSerializer.Deserialize(json, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); } catch (JsonException ex) { throw new InvalidOperationException("Failed to deserialize response", ex); } } }