powered by simpleCommunicator - 2.0.59     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / ASP.Net как получить куки после авторизации?
1 сообщений из 1, страница 1 из 1
ASP.Net как получить куки после авторизации?
    #38696381
MathewSun
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Добрый день.
Делаю клиент, чтобы логиниться на сайт.
Но после пост запроса с авторизацией - куки не приходят, а хочется дальше по сайту ходить авторизованным.

string sURL = string.Empty;
sURL = string.Format(" http://smm-lab.ru/");


CookieCollection cookies = new CookieCollection();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sURL);
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(cookies);
//Get the response from the server and save the cookies from the first request..
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
cookies = response.Cookies;

string getUrl = string.Format(" http://smm-lab.ru/");
string postData = String.Format("login={0}&pass={1}&act={2}", "user", "qwerty", "login");
HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(getUrl);
getRequest.CookieContainer = new CookieContainer();
getRequest.CookieContainer.Add(cookies); //recover cookies First request
getRequest.Method = WebRequestMethods.Http.Post;
getRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
getRequest.AllowWriteStreamBuffering = true;
getRequest.ProtocolVersion = HttpVersion.Version11;
getRequest.AllowAutoRedirect = true;
getRequest.ContentType = "application/x-www-form-urlencoded";

byte[] byteArray = Encoding.ASCII.GetBytes(postData);
getRequest.ContentLength = byteArray.Length;
Stream newStream = getRequest.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();

HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
{
string sourceCode = sr.ReadToEnd();
}

cookies = getResponse.Cookies;
...
Рейтинг: 0 / 0
1 сообщений из 1, страница 1 из 1
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / ASP.Net как получить куки после авторизации?
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]