79103921

Date: 2024-10-18 23:26:00
Score: 0.5
Natty:
Report link

I finally got to connect to sonar from .net using the following code "sonar use Bearer token Authentication":

string responseBody = string.Empty;
var APIUri = "https://sonarcloud.io/";
var VSTSToken = "SonarToken";

// Obtener Listado de proyectos en Azure
uri = "api/issues/search?componentKeys=myproject&impactSeverities=HIGH";
try
{
    using (HttpClient client = new HttpClient())
    {
        client.DefaultRequestHeaders.Accept.Add(
            new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", VSTSToken);
        using (HttpResponseMessage response = await client.GetAsync(APIUri + uri))
        {
            response.EnsureSuccessStatusCode();
            responseBody = await response.Content.ReadAsStringAsync();

        }
    }
}
catch (Exception ex)
{
    //_Logger.LogError(ex.Message);
    //Console.WriteLine(ex.ToString());
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Diego Ahumada Delvillar