title: Using HttpClient, how would I prevent automatic redirects and get original status code and forwading Url in the case of 301
body: <p>I have the following method that returns the <code>Http status code</code> of a given <code>Url</code>:</p>
  
  <pre><code>public static async void makeRequest(int row, string url)
  {
      string result;
      Stopwatch sw = new Stopwatch(); sw.Start();
  
      try
      {
          using (HttpClient client = new HttpClient())
          {
              HttpResponseMessage response = new HttpResponseMessage();
              response = await client.GetAsync(url);
  
              // dump contents of header
              Console.WriteLine(response.Headers.ToString());
  
              if (response.IsSuccessStatusCode)
              {
                  result = ((int)response.StatusCode).ToString();
              }
              else
              {
                  result = ((int)response.StatusCode).ToString();
              }
          }
      }
      catch (HttpRequestException hre)
      {
          result = "Server unreachable";
      }
  
      sw.Stop();
      long time = sw.ElapsedTicks / (Stopwatch.Frequency / (1000L * 1000L));
  
      requestComplete(row, url, result, time);
  }
  </code></pre>
  
  <p>It works well for <code>200</code>/<code>404</code> etc, however in the case of <code>301</code> codes I believe the returned result is the <em>already-redirected</em> (<code>200</code>) result, rather than the actual <code>301</code> that should be returned and which would have a header containing where the redirect would be pointed to.</p>
  
  <p>I have seen something like this in other .Net web requests classes and the technique there was to set some sort of <code>allowAutoRedirect</code> property to false. If this is along the right lines, can anyone tell me the correct alternative for the <code>HttpClient</code> class?</p>
  
  <p><a href="https://stackoverflow.com/questions/690587/using-webclient-in-c-sharp-is-there-a-way-to-get-the-url-of-a-site-after-being-r">This post has info on the above allowAutoRedirect concept I mean</a></p>
  
  <p>Else, how might I get this method to return <code>301s</code> rather than <code>200s</code> for Urls I know to be genuine <code>301s</code>?</p>