title: How to acquire HttpStatus Codes in ASP.Net Core?
body: <p>I'm running through a list of both secure and unsecured domains (both <code>http://</code> and <code>https://</code>) in an array and wish to return their status codes. How is this possible in ASP.Net Core 1.0?</p>
  
  <p>so far, I have</p>
  
  <pre><code>foreach(var item in _context.URLs.ToList())
  {
      // Do something here with item.Domain to check for status
      // For example, if item.Domain was https://example.com..
  }
  </code></pre>
  
  <p>I tried it with regular ASP.Net syntax with this approach:</p>
  
  <pre><code>HttpWebRequest request = (HttpWebRequest)WebRequest.Create(item.Domain);
  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  </code></pre>
  
  <p>The problem is, <code>GetResponse</code> doesn't work in ASP.Net Core </p>
  
  <p>Can anyone help me out with an effecient solution so that the variable returned would be the status? </p>
  
  <p>ex: <code>200</code>, <code>500</code>, <code>404</code>..</p>
  
  <p><strong>EDIT - Here is my full controller AND SOLUTION:</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using Microsoft.AspNetCore.Mvc;
  using MyApp.Models;
  using System.Threading.Tasks;
  using System.Net;
  using System.Net.Http;
  namespace MyApp.Controllers.Api
  {
      public class URLsController : Controller
      {
          private MyAppDBContext _context;
  
          public class newLink
          {
              public string Domain { get; set; }
              public HttpStatusCode Status { get; set; }
          }
  
          public async Task&lt;HttpStatusCode&gt; GetStatusCodes(string url)
          {
              var client = new HttpClient();
              var response = await client.GetAsync(url);
  
              return response.StatusCode;
          }
  
          public URLsController(MyAppDBContext context)
          {
              _context = context;
          }
  
          [HttpPost("api/URLs")]
          public async Task&lt;IActionResult&gt; Post(string url)
          {
              if (url != "")
              {
                  // I pass a URL in through this API and add it to _context.URLs..
                  // I execute a status code check on the URLs after this if statement
              }
  
              List&lt;newLink&gt; list = new List&lt;newLink&gt; ();
  
              foreach (var item in _context.URLs.ToList())
              {
                  newLink t = new newLink();
  
                  t.Domain = item.Domain;
                  t.Status = await GetStatusCodes(item.Domain);
  
                  list.Add(t);
              }
  
              return Ok(list);
          }
      }
  }
  </code></pre>
  
  <p>This returns an array back in this format:</p>
  
  <blockquote>
    <p>[{"Domain":"<a href="https://example1.com/" rel="nofollow noreferrer">https://example1.com/</a>","Status":200},</p>
    
    <p>{"Domain":"<a href="https://example2.com/" rel="nofollow noreferrer">https://example2.com/</a>","Status":200},</p>
    
    <p>{"Domain":"<a href="https://example3.com/" rel="nofollow noreferrer">https://example3.com/</a>","Status":200}]</p>
  </blockquote>