0

[C#] HttpWebRequest not sending Cookies on Windows Phone

Had a similar problem to Jeroen Swart to do with Cookies in Windows Phone as he mentioned in his blog post here.

Basically identical C# code to make a HttpWebRequest with a few cookies would work in a simple desktop app but no cookies would be sent at all in Windows Phone.

My code to add cookies to a CookieContainer:

cookies.Add(new Uri("https://alexanderhoughton.co.uk/"), new Cookie("TestCookie", "TestCookieValue", "/", "alexanderhoughton.co.uk"));

The fix was to remove the path and domain strings from the Cookie constructor! As Jeroen mentioned in his blog, it’s something to do with the ‘.’ prefix etc.

Working Code:

cookies.Add(new Uri("https://alexanderhoughton.co.uk/"), new Cookie("TestCookie", "TestCookieValue"));

Cookies now are sent successfully.