C#Metro HttpClient PostasyncでCookieを受信していません
-
11-12-2019 - |
質問
.NET 4.5 HttpClientを使用してWebサイトにログインしようとしています。私は試してみてCookieContainerをチェックしてからチェックしてクッキーを含まない直前に壊れます。応答は200のステータスを返送します。
private async void Login(string username, string password)
{
try
{
Uri address = new Uri(@"http://website.com/login.php");
CookieContainer cookieJar = new CookieContainer();
HttpClientHandler handler = new HttpClientHandler()
{
CookieContainer = cookieJar
};
handler.UseCookies = true;
handler.UseDefaultCredentials = false;
HttpClient client = new HttpClient(handler as HttpMessageHandler)
{
BaseAddress = address
};
HttpContent content = new StringContent(string.Format("username={0}&password={1}&login=Login&keeplogged=1", username, password));
HttpResponseMessage response = await client.PostAsync(client.BaseAddress, content);
}
.
これが機能していない理由はなぜ手がかりを持っていません。私が.NET 4スタイルを試してみるとうまく機能します。
所属していません StackOverflow