title: c# HttpWebRequest "POST" with Loop
body: <p>I wanted do <code>POST</code> a <code>WebRequest</code> for a Browser game in a loop because the <code>POST</code> content contains a number. Now I have a frozen program.</p>
  
  <p>Here is my Code:</p>
  
  <pre><code>String loginData = "login";
  
  // Set Cookie 
  CookieContainer cookieContainer = new CookieContainer();
  
  // Login
  
  HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("URL");
  req.CookieContainer = cookieContainer;
  req.Method = "POST";
  req.ContentType = "application/x-www-form-urlencoded";
  ASCIIEncoding encoding = new ASCIIEncoding();
  byte[] loginDataBytes = encoding.GetBytes(loginData);
  req.ContentLength = loginDataBytes.Length;
  Stream stream = req.GetRequestStream();
  stream.Write(loginDataBytes, 0, loginDataBytes.Length);
  stream.Close();
  HttpWebResponse res = (HttpWebResponse)req.GetResponse();
  
  // Start the Loop
  
  for (int i=1; i &lt; 10; i++)
  {
  
      String Friendly = "frday=" + i;
  
      req = (HttpWebRequest)HttpWebRequest.Create("URL");
      req.CookieContainer = cookieContainer;
      req.Method = "POST";
      req.ContentType = "application/x-www-form-urlencoded";
      byte[] Fr = encoding.GetBytes(Friendly);
      req.ContentLength = Fr.Length;
  
      Stream stream = req.GetRequestStream();
      stream.Write(Fr, 0, Fr.Length);
      stream.Close();
  
      Console.WriteLine("FriendlyNr: " + i);
  }
  </code></pre>
  
  <p>The Ouput is:</p>
  
  <blockquote>
    <p>FriendlyNr: 1</p>
  </blockquote>
  
  <p>And the Browsergame got only the one Post Content.</p>
  
  <p>So the first run is working but the second rund did not work. The Programm freezes at </p>
  
  <pre><code>Stream stream = req.GetRequestStream();
  </code></pre>
  
  <p>I want to loop 10 times. How to achieve that?</p>