title: C# how to get the JSON string by using HttpWebRequest
body: <p>Anybody help me to get the JSON from the gitlab site. I have written my code but when I compile the code I receiving the exception <code>The remote server returned an error: (401) Unauthorized.</code> in my console application (C#).</p>
  
  <p>In my browser, I run the same URL when the I signed in the browser, I can able to get the JSON string. If I run the same URL after signed out from the browser I get <code>{"message":"401 Unauthorized"}</code> message in my browser. </p>
  
  <p>Due to this same exception, I think that I did not pass the username and credential into my <code>HttpWebRequest</code>.</p>
  
  <p>I getting the exception in the line <code>HttpWebResponse response = request.GetResponse() as HttpWebResponse;</code></p>
  
  <p>My code:</p>
  
  <pre><code>            string URL = "http://gitlab.company.com/api/v3/users?per_page=100&amp;page=1";  
              HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
              request.ContentType = "application/json; charset=utf-8";
              request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes("userName:passWord"));
              request.PreAuthenticate = true;
              HttpWebResponse response = request.GetResponse() as HttpWebResponse;
              using (Stream responseStream = response.GetResponseStream())
              {
                  StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                  Console.WriteLine(reader.ReadToEnd());
              }
  </code></pre>
  
  <p><strong>My question:</strong></p>
  
  <ol>
  <li>What and where did I made a mistake?</li>
  <li>I know I have to use the GET verb to get the data in API but I don`t know where I have to use the GET verb?</li>
  </ol>
  
  <p>Thanks in advance.</p>