title: Retrieving multiple "Set-Cookie" headers from a HttpWebResponse
body: <p>I'm attempting to programmatically log in to the Yahoo developer API. I've hit a stumbling block where I can't access all of the "Set-Cookie" headers of a HttpWebResponse. </p>
  
  <p>Fiddler shows me the following cookies in the header of the response:</p>
  
  <pre><code>Set-Cookie: B=733jjvp7f5g8f&amp;b=4&amp;d=1pFN8bVpYFYaPUme88.fc6ZzTSI-&amp;s=kc&amp;i=.1p3Ei3yvwqZjo0gcg7D; expires=Sun, 22-Dec-2013 05:33:04 GMT; path=/; domain=.yahoo.com
  Set-Cookie: F=a=GYsABKAMvTZoTcNAPKUXrclX_Hb77EA7I_62nONz8QeEwNevHwqJ_NyizED88uhv9aMx.9o-&amp;b=3tN5; expires=Sun, 22-Dec-2013 05:33:04 GMT; path=/; domain=.yahoo.com
  Set-Cookie: Y=v=1&amp;n=0v251rt3ifppb&amp;l=0kii84if0h70ma/o&amp;p=m2fvvau012000000&amp;iz=1111&amp;r=if&amp;lg=en-AU&amp;intl=au&amp;np=1; path=/; domain=.yahoo.com
  Set-Cookie: PH=fn=jW23i4lnq1UpiP.lsuU-&amp;l=en-AU; expires=Sun, 22-Dec-2013 05:33:04 GMT; path=/; domain=.yahoo.com
  Set-Cookie: T=z=QEs8OBQYTBPBEZq31nTCqv1MzNPBjUwTjcwMDZOTjY-&amp;a=YAE&amp;sk=DAAtoxgrYmWIMk&amp;ks=EAA3Ha0H7qyCT8P3cI9NWJrIA--~E&amp;d=c2wBTkRRNEFUSTNPVEEzTnpFNU9URS0BYQFZQUUBZwFCRFZQTkRSSjJQRVRDTEdFT0xCQ1hER0VVUQFvawFaVzAtAXRpcAF2MkNUVUEBenoBUUVzOE9CQTdF; path=/; domain=.yahoo.com
  Set-Cookie: SSL=v=1&amp;s=kTc532PQYAe1iT.23Q55E50ZdoOAdEK_fshc3g_YZ3SxszcbuHkmpJUAQ7RT67nDNA0nXyX68um90ZuS9RQztQ--&amp;kv=0; path=/; domain=.yahoo.com; secure; httponly
  </code></pre>
  
  <p>However, I'm unable to access anything beyond the first instance of "Set-Cookie" via .NET:</p>
  
  <pre><code>// Make the web request:
  var userAuthWebRequest = WebRequest.Create(uri) as HttpWebRequest;
  var response = userAuthWebRequest.GetResponse() as HttpWebResponse;
  
  // Dump the headers to debug:
  Debug.WriteLine(string.Format("Set-Cookie: {0}", response.Headers.Get("Set-Cookie")));
  </code></pre>
  
  <p>My debug output returns:</p>
  
  <pre><code>Set-Cookie: B=733jjvp7f5g8f&amp;b=3&amp;s=b1; expires=Sun, 22-Dec-2013 05:33:03 GMT; path=/; domain=.yahoo.com
  </code></pre>
  
  <p>Interestingly, if I make a similar request to Headers.GetValues, it actually returns two instances of the "Set-Cookie" header, which appear to have been concatenated together above:</p>
  
  <pre><code>foreach (var headerName in response.Headers.AllKeys)
  {
      foreach (var values in response.Headers.GetValues(headerName))
      {
          Debug.WriteLine("{0}: {1}", headerName, values);
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Set-Cookie: B=733jjvp7f5g8f&amp;b=3&amp;s=b1; expires=Sun
  Set-Cookie: 22-Dec-2013 05:33:03 GMT; path=/; domain=.yahoo.com
  </code></pre>
  
  <p>I've seen a few other questions that confirm the raw headers aren't available via the HttpWebResponse object, and I should investigate using a sockets solution. I'm about to check out FiddlerCore to see if I have any luck with that, but if anyone has any other pointers I'd love to see them.</p>
  
  <p>Thanks!</p>