I have problem. I have code on the main page:
private async Task<string> Login(string username, string password)
{
try
{
string url = "myurl.com/page1";
Uri address = new Uri(url);
var postData = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("Login", username),
new KeyValuePair<string, string>("Password", password)
};
CookieContainer cookieJar = new CookieContainer();
HttpContent content = new FormUrlEncodedContent(postData);
var handler = new HttpClientHandler
{
CookieContainer = cookieJar,
UseCookies = true,
UseDefaultCredentials = false
};
var client = new HttpClient(handler)
{
BaseAddress = address
};
HttpResponseMessage response = await client.PostAsync(url, content);
string UrlBase = "myurl.com/page1";
Uri uri = new Uri(UrlBase);
var responseCookies = cookieJar.GetCookies(uri);
foreach (Cookie cookie in responseCookies)
{
string cookieName = cookie.Name;
string cookieValue = cookie.Value;
}
response.EnsureSuccessStatusCode();
string body = await response.Content.ReadAsStringAsync();
return body;
}
catch (Exception e)
{
return e.ToString();
}
}
But in debug I cant see cookies. And his number is 0. And I don`t know, how can I get myurl.com/page2 on the Page2.xaml? How to use and save cookies?
How to get and set cookies for Windows Phone 8
http://msdn.microsoft.com/en-us/library/windowsphone/develop/dd920298(v=vs.105).aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.