【发布时间】:2016-02-01 16:38:00
【问题描述】:
我需要一些关于新 Windows.Web.Http.HttpClient 类的帮助。我现在正在编写我的第一个 WP8.1 应用程序,它让我发疯。我正在登录这样的网站:
var values = new Dictionary<string, string>();
values.Add("login_username", _username);
values.Add("login_password", _password);
values.Add("login_lifetime", "36000");
var parameters = new HttpFormUrlEncodedContent(values);
var response = await Forum.Http.PostAsync(new Uri("http://foo.bar.xyz"), parameters);
var buffer = await response.Content.ReadAsBufferAsync();
byte[] byteArray = buffer.ToArray();
string content = Encoding.UTF8.GetString(byteArray, 0, byteArray.Length);
if (content.Contains("Wrong password/user name"))
{
return false;
}
return true;
这很好用。我的 HttpClient 是一个静态字段,像这样:
public static HttpBaseProtocolFilter Filter = new HttpBaseProtocolFilter();
public static HttpClient Http = new HttpClient(Filter);
登录工作正常,但它不会保存网站在登录后发送的 cookie。如何保存它们,我可以在每次 GetAsync() 时将它们发送到网站吗?
【问题讨论】:
标签: c# .net cookies windows-runtime httpclient