title: Authorize SonarQube api
body: <p>I am trying to use an Api to get the value of some metrics with a c# application. My code looks like this: </p>
  
  <pre><code>var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://myServer/api/measures/component?componentKey=myProject&amp;metricKeys=bugs,new_bugs");
              httpWebRequest.Headers.Add("Authorization", token);
              httpWebRequest.ContentType = "application/json";
              httpWebRequest.Method = "GET";
              try
              {
                  var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                  string result;
                  using (var streamreader = new StreamReader(httpResponse.GetResponseStream()))
                  {
                      result = streamreader.ReadToEnd();
                  }
  
                  var joResponse = JObject.Parse(result);
                  var measures = (JArray)joResponse["component"]["measures"];
  
              }
              catch (Exception e)
              {
                  Console.WriteLine(e);
                  throw;
              }
  </code></pre>
  
  <p>When i write the same API into the address box of my browser, i get the result i looked for. And the token for the header is generated by my server. But for some reason I catch an error 401 when trying to get the response for this httpwebrequest in the code. What am I doing wrong?</p>
  
  <p>Alternatively, instead of using a token, I tried using credentials:</p>
  
  <pre><code>httpWebRequest.Credentials = new NetworkCredential(name, password);
  </code></pre>
  
  <p>The result was the same. </p>
  
  <p>EDIT:</p>
  
  <p>I tried to use the header </p>
  
  <p><code>httpWebRequest.Headers.Add("Authorization", "Bearer " + token);</code></p>
  
  <p>instead. This also didn't work out.</p>