| 123456789101112131415161718192021222324 |
- using Grpc.Net.Client;
- using Microsoft.Net.Http.Headers;
- using Newtonsoft.Json;
-
- namespace SpotifyService.HttpUtils
- {
- public static class HttpUtils<T>
- {
- public static async Task<T> GetData(HttpClient client, string url, string token)
- {
- //add header
- client.DefaultRequestHeaders.Add(HeaderNames.Authorization, "Bearer " + token);
-
- //get request
- var req = await client.GetAsync(url);
-
- //read response
- var response = JsonConvert.DeserializeObject<T>(await req.Content.ReadAsStringAsync())!;
-
- return response;
-
- }
- }
- }
|