title: HttpWebResponse 401-error Unauthorized
body: <p>I'm currently having issues with a HttpWebRequest/Response when I'm trying to make calls to an API.</p>
  
  <p>The API use JSON/Ajax to make calls, but I need to make the calls through HttpWebRequest/Response which I don't fully understand and I think I'm passing the wrong access token.</p>
  
  <p>Here's my current code, which I got from a tutorial:</p>
  
  <pre><code>        byte[] buffer = Encoding.ASCII.GetBytes("username=User&amp;password=Password");
  
          HttpWebRequest WebReq =(HttpWebRequest)WebRequest.Create("http://api40.maildirect.se/User/Authorize");
  
          WebReq.Method = "POST";
          WebReq.ContentType = "application/x-www-form-urlencoded";
          WebReq.ContentLength = buffer.Length;
  
          Stream PostData = WebReq.GetRequestStream();
  
          PostData.Write(buffer, 0, buffer.Length);
          PostData.Close();
  
          HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
  
          var status = WebResp.StatusCode; (returns OK)
  
          Stream _Answer = WebResp.GetResponseStream();
          StreamReader Answer = new StreamReader(_Answer);
  
          //Here I try to make another request, do I need to make another instance?
          WebReq = (HttpWebRequest)WebRequest.Create("http://api40.maildirect.se/Contacts?&amp;select=ContactId,FirstName,LastName");
          WebReq.Method = "GET";
          WebReq.ContentType = "text/json; charset=utf-8";
          WebReq.Headers.Add("Authorization", Answer.ReadToEnd());
  
          HttpWebResponse WebResp2 = (HttpWebResponse)WebReq.GetResponse();
  
           ^ This is where it breaks because I'm not authorized.
  </code></pre>
  
  <p>And the only useful documentation from the API is that I need to pass the access token when making additional calls, but I suspect I'm passing the wrong token. </p>
  
  <p>Thanks in advance</p>
  
  <p>deSex</p>