title: HttpWebRequest Cookie Issue - (500) Internal Server Error
body: <p>I've recently run into an issue which I believe is related with the CookieContainer.
  It is a basic HttpWebRequest to a url that was previously working fine (2 days ago) but is now having issues.<br/>
  Below is the code I am using.</p>
  
  <pre><code>string url = "http://www.footywire.com/afl/footy/ft_match_statistics?mid=5827";
  
  var cookieJar = new CookieContainer(); 
  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 
  request.CookieContainer = cookieJar;
  
  request.AllowAutoRedirect = false;
  request.Method = "GET";
  request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0";
  request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
  
  WebHeaderCollection myWebHeaderCollection = request.Headers;
  myWebHeaderCollection.Add("Accept-Encoding", "gzip, deflate");
  myWebHeaderCollection.Add("Accept-Language", "en-US,en;q=0.5");
  
  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  int cookieCount = cookieJar.Count;
  response.Close();
  </code></pre>
  
  <p>I am getting a (500) Internal Server Error during the GetResponse() call.
  The URL works fine in the browser, but fails if I use an incognito/private window which makes me think it has to be cookie related.</p>
  
  <p>I've monitored the request/responses using fiddler and can see the request is not handling cookies at all.</p>
  
  <p>Here is a working request through the browser with cookies enabled.</p>
  
  <pre><code>GET http://www.footywire.com/afl/footy/ft_match_statistics?mid=5827 HTTP/1.1
  Host: www.footywire.com
  User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Accept-Language: en-US,en;q=0.5
  Accept-Encoding: gzip, deflate
  Cookie: __utma=123692316.616048912.1368166198.1400452319.1400457786.25; __gads=ID=c95b71c78d8a7516:T=1368166203:S=ALNI_MbHrLnKztzLrfUEkZNoQfcimetGNw; _em_vt=3938ffa289939f5bd80fd60798185181c3303dddd6-9262208553794a3e; __utmz=123692316.1395356585.4.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmc=123692316; JSESSIONID=62B598BD99DC2D228C4FC1E1549ED6FB; __utmb=123692316.1.10.1400457786; _em_v=5cc514d9ac92155cd445ac583ffd53794a3e7088d0-4657961653794a3e
  Connection: keep-alive
  </code></pre>
  
  <p>This is the request the code is sending. The cookie is clearly missing.</p>
  
  <pre><code>GET http://www.footywire.com/afl/footy/ft_match_statistics?mid=5827 HTTP/1.1
  User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Accept-Encoding: gzip, deflate
  Accept-Language: en-US,en;q=0.5
  Host: www.footywire.com
  Connection: Keep-Alive
  </code></pre>
  
  <p>I'm at a bit of a loss as to why its not working now, but it was 2 days ago. I'm also not sure of what to do next.</p>
  
  <p>Any help would be appreciated. Thanks.</p>