Я пытаюсь войти на сайт через webrequest, но webresponse возвращает тот же html страницы входа.C# - попытка входа в систему с помощью webrequest, но webresponse возвращает тот же html
CookieContainer cookies = new CookieContainer();
String postData = "vb_login_username=myusername&vb_login_password=mypassword";
byte[] send = Encoding.Default.GetBytes(postData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("domain url here"));
request.CookieContainer = cookies;
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.Timeout = 30000;
request.ContentLength = send.Length;
Stream stream = request.GetRequestStream();
stream.Write(send, 0, send.Length);
stream.Flush();
stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
foreach (Cookie cook in response.Cookies)
{
cookies.Add(cook);
Console.WriteLine(cook.Name+ cook.Value+ cook.Path+ cook.Domain);
}
StreamReader reader = new StreamReader(response.GetResponseStream());
String result = reader.ReadToEnd();
Console.WriteLine(result);
Трудно ответить без фактического примера. Попробуйте 'Encoding.UTF8' вместо' Encoding.Default'. –