title: check if a website is working error"The remote name could not be resolved"
body: <p>I'm trying to check if a website is online and taking urls from mssql server 2008 and if said website is not working, my code should send an e-mail. </p>
  
  <p>It is working fine there is no problem with taking data from server but if I try to check a not working website for example <code>http://blabalabalabal.com</code> it gives me an error like: <strong>Object reference not set to an instance of an object.</strong>
  on this line:if (response.StatusCode != HttpStatusCode.OK)</p>
  
  <p>How can I solve this?</p>
  
  <pre><code>        string connectionString = "Data Source=eur-vpc\\sqlexpress;Integrated Security=True;Initial Catalog=Website";
          SqlConnection connection = new SqlConnection(connectionString);
          connection.Open();
          SiteeeID = Convert.ToInt32(listBox1.SelectedValue);
          string url = "select http from AyrintiSite where SiteID='" + SiteeeID + "'";
          connection.Close();
          ArrayList Sites = new ArrayList();
          using (SqlConnection cn = new SqlConnection(connectionString))
          {
              using (SqlCommand cm = new SqlCommand(url, cn))
              {
                  cn.Open();
                  SqlDataReader reader = cm.ExecuteReader();
                  while (reader.Read())
                  {
                      Sites.Add(reader.GetString(0));
                  }
  
              }
          }
       for (int i = 0; i &lt; Sites.Count; i++)
          {
  
              string url2 = Sites[i].ToString();
              HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(url2));
            //  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
             // string gelenYanit = response.StatusCode.ToString();
              var response = GetResponse(request);
              if (response.StatusCode != HttpStatusCode.OK)
              {
                      MailMessage mail = new MailMessage();
                      SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
                      mail.From = new MailAddress("blabla@gmail.com");
                      mail.To.Add("blabla2@yandex.com");
                      mail.Subject = "Website";
                      mail.Body += "Website is not working";
                      mail.IsBodyHtml = true;
                      SmtpServer.Port = 587;
                      SmtpServer.Credentials = new System.Net.NetworkCredential("blabla@gmail.com", "******");
                      SmtpServer.EnableSsl = true;
                      SmtpServer.Send(mail);
                      MessageBox.Show("Mail send");
  
                  }
  
          }
      }
  
      private HttpWebResponse GetResponse(HttpWebRequest request)
      {
          try
          {
              return (HttpWebResponse)request.GetResponse();
  
          }
          catch (System.Net.WebException e)
          {
              if (e.Response == null)
              {
                  MailMessage mail = new MailMessage();
                  SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
                  mail.From = new MailAddress("blabla@gmail.com");
                  mail.To.Add("blabla2@yandex.com");
                  mail.Subject = "Website";
                  mail.Body += "Website is not working";
                  mail.IsBodyHtml = true;
                  SmtpServer.Port = 587;
                  SmtpServer.Credentials = new System.Net.NetworkCredential("blabla@gmail.com", "********");
                  SmtpServer.EnableSsl = true;
                  SmtpServer.Send(mail);
                  MessageBox.Show("Mail send");
              }
             return (HttpWebResponse)e.Response;
          }
  </code></pre>