Vediamo se riesco ad essere chiaro :
questo è un pezzo di codice che ottiene il token con successo :
Async Function Authenticate() As Task(Of Boolean)
Using client As New HttpClient()
Dim authUrl As String = FORMA_LMS_URL & API_AUTH_ENDPOINT
' Creazione dell'Authorization Header
Dim authCode As String = Convert.ToBase64String(Encoding.UTF8.GetBytes(API_KEY & ":" & API_SECRET))
client.DefaultRequestHeaders.Add("X-Authorization", "FormaLMS " & authCode)
client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"))
' Parametri della richiesta POST
Dim postData As New Dictionary(Of String, String) From {
{"username", "XXXXXXXXX"},
{"password", "XXXXXXXXXX"}
}
Dim content As New FormUrlEncodedContent(postData)
' Effettua la richiesta
Dim response As HttpResponseMessage = Await client.PostAsync(authUrl, content)
Dim responseText As String = Await response.Content.ReadAsStringAsync()
' Analizza la risposta XML
Dim xmlDoc As XDocument = XDocument.Parse(responseText)
Dim success As String = xmlDoc.Root.Element("success").Value
If success.ToLower() = "true" Then
token = xmlDoc.Root.Element("token").Value
Return True
Else
Console.WriteLine("

Errore nell'autenticazione: " & xmlDoc.Root.Element("message").Value)
Return False
End If
End Using
End Function
mentre questa è una chiamata ( lista utenti ) api
Async Function GetUserList() As Task(Of String)
Using client As New HttpClient()
Dim listUserUrl As String = FORMA_LMS_URL & API_LISTUSER_ENDPOINT
' Verifica che il token sia disponibile
If String.IsNullOrEmpty(token) Then
Return "

Errore: Token non disponibile. Effettua prima l'autenticazione."
End If
' Imposta l'header di autenticazione con il token
client.DefaultRequestHeaders.Add("X-Authorization", "FormaLMS " & token)
client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"))
' Effettua la richiesta HTTP GET
Dim response As HttpResponseMessage = Await client.GetAsync(listUserUrl)
Return Await response.Content.ReadAsStringAsync()
End Using
End Function
dove API_LISTUSER_ENDPOINT è : "/api/user/userslist"
e FORMA_LMS_URL è :
https://elearning.miosito.xxx/
prima ottengo il token e subito dopo faccio la chiamata , ma ottengo sempre :
<?xml version="1.0" encoding="UTF-8"?><XMLoutput><error>Autentication Token is not valid</error></XMLoutput>
Grazie