title: How to fix this Timer tick error in C#?
body: <p>I am using this code to receive data from an Internet address. However, when the timer ticks at first time the connection is OK and program works properly. <strong>But in second time, an error is raised from this line</strong>:</p>
  
  <pre><code>HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  </code></pre>
  
  <p>I want to know how to fix this problem.</p>
  
  <p>Timer interval is 30 seconds.</p>
  
  <p>Code:</p>
  
  <pre><code>private void timer1_Tick(object sender, EventArgs e)
  {
      WebRequest request = WebRequest.Create("http://localhost  
      /go/online.asp?prog=y&amp;rln=" + Properties.Settings.Default.cos);
  
      request.Credentials = CredentialCache.DefaultCredentials;
  
      HttpWebResponse response = (HttpWebResponse)request.GetResponse();
      Stream dataStream = response.GetResponseStream();
      StreamReader reader = new StreamReader(dataStream);
  
      string responseFromServer = reader.ReadToEnd();
  
      reader.Close();
      dataStream.Close();
      response.Close();
  }
  </code></pre>
  
  <p>Error:
  WebException was unhandled. 
  The remote server returned an error: (500) Internal Server Error.</p>