CookieContainer Support - HttpRequestMessage / HttpResponseMessage

Topics: Web Api
Mar 3, 2011 at 6:11 PM

Hi guys...

I was curious if it was on the agenda to build in CookieContainer support for HttpRequestMessage & HttpResponseMessage.  I was going to create a decorator to add this functionality but would have to duplicate the logic of the existing parser. Thanks.

Mar 4, 2011 at 2:30 AM

There is a CookieContainer, it's just well hidden :-).  You need to create a class derived from WebRequestChannel and that class will have a CookieContainer that you can set.  In order to use the class you need to set HttpClient.Channel to your custom channel.  

You will find you need to use this approach to set a bunch of properties like CachePolicy, ClientCertificates, AutoRedirect, AutoDecompression.  You can think of this custom channel as being a way to package together a set of config settings into a reusable class.  Not the most obvious solution but it seems to work quite well.