Отправка POST запроса и получение куки - C#
Формулировка задачи:
Стоит задача залогиниться на сайте https://lk2.service.nalog.ru/lk/index.html, используя метод POST (функция ниже), однако в ответ получаю все ту же страницу. Как в ответ получить куки?
POST("https://lk2.service.nalog.ru/lk/index.html", "username=000000000000&password=12345&__checkbox_rememberMe=true");
private string POST(string Url, string Data)
{
WebRequest req = WebRequest.Create(Url);
req.Method = "POST";
req.Timeout = 100000;
req.ContentType = "application/x-www-form-urlencoded";
byte[] sentData = Encoding.GetEncoding(1251).GetBytes(Data);
req.ContentLength = sentData.Length;
Stream sendStream = req.GetRequestStream();
sendStream.Write(sentData, 0, sentData.Length);
sendStream.Close();
WebResponse res = req.GetResponse();
Stream ReceiveStream = res.GetResponseStream();
StreamReader sr = new StreamReader(ReceiveStream, Encoding.UTF8);
Char[] read = new Char[256];
int count = sr.Read(read, 0, 256);
string Out = String.Empty;
while (count > 0)
{
String str = new String(read, 0, count);
Out += str;
count = sr.Read(read, 0, 256);
}
return Out;
}Решение задачи: «Отправка POST запроса и получение куки»
textual
Листинг программы
Неявное преобразование типа "System.Net.CookieCollection" в "System.Net.CookieContainer" невозможно