title: Call authorized Web API using WebClient
body: <p>After hours of searching the internet I decided to ask you guys for a little help.</p>
  
  <p>I've written an Web API with couple of simple get/post methods. I'm using Individual user accounts authentication method.</p>
  
  <p>Using the HttpClient I've managed to successfully call every AUTHORIZED get and post method as well as the /token endpoint used for generating authorization token.</p>
  
  <p>The problem is that I must call these methods inside .NET Framework 3.5 project. So I've tried using WebClient to do this because I read that the HttpClient is not supported in .NET Framework 3.5. </p>
  
  <p>GetAPIToken() METHOD generates Bearer token and it works.</p>
  
  <pre><code> private static string GetAPIToken(string userName, string password, string apiBaseUri)
      {
          using (WebClient client = new WebClient())
          {
              client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
              var response = client.UploadString(apiBaseUri + "/Token", "POST", "grant_type=password&amp;username=" + userName + "&amp;password=" + password);
              var jObject = JObject.Parse(response);
              return jObject.GetValue("access_token").ToString();
          }
      }
  </code></pre>
  
  <p>This GET method works when I remove [Authorize] attribute from the Web API but I can't make it work when authorized.</p>
  
  <pre><code>    //GET ODRAĐENI POSTUPCI
      private static string GetOdradjeniPostupci(int Id, string token)
      {
          string apiBaseUri = "http://localhost:60511/";
          string serviceUrl = apiBaseUri + "api/ZOdradjeniPostupci";
  
          using (WebClient client = new WebClient())
          {
              client.Headers.Clear();
              client.Headers.Add("Content-Type", "application/json");
              client.Headers.Add("Authorization", "Bearer " + token);
              var response = client.DownloadString(serviceUrl + "/GetZOdradjeniPostupci?cZdrUst=" + Id.ToString());
  
              return response;
          }
      }
  </code></pre>
  
  <p>I get error 401 unathorized no matter what I try. (Different combinations from the internet regarding Authorization header).
  Hope you could give me any advice on how to solve this.</p>
  
  <p>I would appreciate it a lot.</p>
  
  <p>Thanks.</p>