reorg
This commit is contained in:
parent
d000f77098
commit
40e8e08690
3487 changed files with 39 additions and 21 deletions
20
src/Yavsc.Web/Helpers/HttpContextHelpers.cs
Normal file
20
src/Yavsc.Web/Helpers/HttpContextHelpers.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using System.Net.Http.Headers;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
|
||||
namespace Yavsc.WebApiClient.Helpers;
|
||||
|
||||
public static class HttpContextHelpers
|
||||
{
|
||||
public static async Task<string> GetJson(this HttpContext httpContext, string endPoint)
|
||||
{
|
||||
var accessToken = await httpContext.GetTokenAsync("access_token");
|
||||
var client = new HttpClient(new HttpClientHandler() { AllowAutoRedirect = false });
|
||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
|
||||
var content = await client.GetAsync(endPoint);
|
||||
content.EnsureSuccessStatusCode();
|
||||
var json = await content.Content.ReadAsStringAsync();
|
||||
return json;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue