cambios en apidenuncias
This commit is contained in:
40
.codex-links/WebIntranet/Models/UtilAntifraude.vb
Normal file
40
.codex-links/WebIntranet/Models/UtilAntifraude.vb
Normal file
@@ -0,0 +1,40 @@
|
||||
Imports Microsoft.Extensions.Configuration
|
||||
Imports Microsoft.IdentityModel.Clients.ActiveDirectory
|
||||
Imports Newtonsoft.Json
|
||||
Imports System.Net.Http
|
||||
Imports System.Net.Http.Headers
|
||||
Imports System.Threading.Tasks
|
||||
|
||||
Public Class UtilAntifraude
|
||||
|
||||
Private Shared Property Conf As IConfiguration
|
||||
Public Shared Function CheckCred() As Boolean
|
||||
If HttpContext.Current.Session("persona") IsNot Nothing Then
|
||||
Return True
|
||||
Else
|
||||
Return False
|
||||
End If
|
||||
End Function
|
||||
Public Shared Async Function ObtenerObjeto(Of T)(ByVal cliente As HttpClient, ByVal uri As String) As Task(Of T)
|
||||
Dim response = Await cliente.GetAsync(uri)
|
||||
|
||||
If response.IsSuccessStatusCode Then
|
||||
Dim resultContent = Await response.Content.ReadAsStringAsync()
|
||||
Return JsonConvert.DeserializeObject(Of T)(resultContent)
|
||||
Else
|
||||
Return Nothing
|
||||
End If
|
||||
End Function
|
||||
Public Shared Function ObtenerCliente(ByVal token As String, ByVal clientFactory As IHttpClientFactory) As HttpClient
|
||||
Dim client = clientFactory.CreateClient()
|
||||
client.BaseAddress = New Uri(urlSwagger())
|
||||
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("Bearer", token)
|
||||
client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json"))
|
||||
Return client
|
||||
End Function
|
||||
Public Shared Function urlSwagger() As String
|
||||
'Conf = New ConfigurationBuilder().AddJsonFile("appsettings.json").Build()
|
||||
Dim swagger As String = ConfigurationManager.AppSettings("SwaggerVB")
|
||||
Return swagger
|
||||
End Function
|
||||
End Class
|
||||
Reference in New Issue
Block a user