title: Cookies dropped / lost on HttpWebRequest GetReponse
body: <p>Occasionally my program appeared to fail on making an HTTP Post. I narrowed this down to a cookie apparently being lost.</p>
  
  <p>Some investigation, I narrowed it down</p>
  
  <pre><code>HttpWebResponse response = (HttpWebResponse)http.GetResponse();
  </code></pre>
  
  <p>Strange thing is, it doesn't happen all the time, typically when this method is first run, then everything is ok (after I force the re-addition of this cookie.</p>
  
  <p>I have seemingly hacked a solution together that works for this case (but I am concerned it will break other cases, as is usually the way with hack solutions).</p>
  
  <pre><code>var cookiesPrePull = cookies.GetCookies(http.RequestUri);
  HttpWebResponse response = (HttpWebResponse)http.GetResponse();
  foreach (Cookie cookiePre in cookiesPrePull)
  {
      bool bExist = false;
      foreach (Cookie cookiePost in cookies.GetCookies(http.RequestUri))
      {
          if (cookiePre.Name == cookiePost.Name)
          {
              bExist = true;
              break;
          }
      }
      if (!bExist)
      {
          cookies.Add(cookiePre);
      }
  }
  </code></pre>
  
  <p>What I am trying to understand is why the cookie is dropped by the GetResponse call. Examining in Fiddler, nothing is mentioned about this cookie. The only cookie code is to set two cookies. One already exists, one doesn't.</p>
  
  <p>The cookie definitely hasn't expired. Am at a complete loss over this</p>
  
  <p>cheers</p>