I have to do forms authentication to use a service, but I can't get cookie. One solution is every time did two requests one to login page and one to resource I want to get. I did the same thing on wpf and console apps and it works well but not in windows phone 8. here is my code.
CookieContainer cookies = new CookieContainer();
HttpClientHandler handler = new HttpClientHandler();
handler.CookieContainer = cookies;
HttpClient client = new HttpClient(handler);
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("username", "someusername"),
new KeyValuePair<string, string>("password", "somepassword")
});
var response = await client.PostAsync("mysite.com/login", content);
string res = await client.GetStringAsync("mysite.com/posts/getposts");
Uri uri = new Uri("mysite.com/");
var responseCookies = cookies.GetCookies(uri);
foreach (Cookie cookie in responseCookies)
{
string name = cookie.Name;
string value = cookie.Value;
}