Авторизация на сайте ппри помощи post-запроса - C#
Формулировка задачи:
На сайте есть форма входа:
Браузер отправляет запрос такого вида: см. миниатюру.
Я отсылаю запрос таким кодом:
Т.е. чтобы авторизироваться я делаю так:
Но, авторизация не осуществляется. В чем проблема? Заранее спасибо.
<td class="bc"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td width="40%"><form action="./login.php" method="post">
<table width="100%" border="0" cellpadding="0" cellspacing="5"><td><input type="text" name="user_name" class="logininput" value="Логин" onblur="if(this.value=='') this.value='Логин';" onfocus="if(this.value=='Логин') this.value='';" /></td>
<tr>
<td><input type="password" name="user_password" class="logininput" value="Пароль" onblur="if(this.value=='') this.value='Пароль';" onfocus="if(this.value=='Пароль') this.value='';" /></td>
<tr>
<td><table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input type="checkbox" name="auto_login" value="1" /></td>
<td> Запомнить меня</td>
</tr>
</table></td>
<tr>
<td><input type="submit" value="Войти" class="button" style="width: 120px;"/></td>
</table></form>
</td>
public static string PostData(string file, string ContentType, string data)
{
System.Net.WebRequest reqPOST = System.Net.WebRequest.Create(file);
reqPOST.Method = "POST"; // Устанавливаем метод передачи данных в POST
reqPOST.Timeout = 120000; // Устанавливаем таймаут соединения
reqPOST.ContentType = ContentType; // указываем тип контента
byte[] sentData = System.Text.Encoding.Default.GetBytes(data);
reqPOST.ContentLength = sentData.Length;
System.IO.Stream sendStream = reqPOST.GetRequestStream();
sendStream.Write(sentData, 0, sentData.Length);
sendStream.Close();
System.Net.WebResponse result = reqPOST.GetResponse();
string html = new System.IO.StreamReader(result.GetResponseStream(), System.Text.Encoding.Default).ReadToEnd();
return html;
}PostData("http://gallery.pitnet.ru/", "application/x-www-form-urlencoded", "user_name=логин&user_password=пароль&auto_login=1");Решение задачи: «Авторизация на сайте ппри помощи post-запроса»
textual
Листинг программы
PostData("http://gallery.pitnet.ru/login.php", "application/x-www-form-urlencoded", "user_name=логин&user_password=пароль&auto_login=1");