Показать сообщение отдельно

  #4  
Старый 14.03.2010, 02:37
WAYS
Познающий
Регистрация: 12.11.2008
Сообщений: 33
Провел на форуме:
67053

Репутация: 15
Отправить сообщение для WAYS с помощью ICQ
По умолчанию

Сделал
Код:
        public string aut()
        {
            var url = "http://site.com/login.php";
            var postData = "username=" + tb_login.Text + "&password=" + tb_pass.Text;
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            string Cookies = null;
            httpWebRequest.AllowAutoRedirect = false;
            httpWebRequest.Method = "POST";
            httpWebRequest.ContentType = "application/x-www-form-urlencoded";
            var buffer = Encoding.ASCII.GetBytes(postData);
            httpWebRequest.ContentLength = buffer.Length;
            try
            {
                using (var writer = httpWebRequest.GetRequestStream())
                {
                    writer.Write(buffer, 0, buffer.Length);
                }
                using (var httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse())
                {
                    Settings1.Default.global_cookie = string.IsNullOrEmpty(httpWebResponse.Headers["Set-Cookie"]) ? "" : httpWebResponse.Headers["Set-Cookie"];
                    Settings1.Default.Save();
                    url = httpWebResponse.Headers.Get("Location") ?? "";
                }
                httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                httpWebRequest.Method = "GET";
                if (!string.IsNullOrEmpty(Cookies))
                {
                    httpWebRequest.Headers.Add(HttpRequestHeader.Cookie, Cookies);
                }
                using (var httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse())
                {
                    Settings1.Default.cookie = string.IsNullOrEmpty(httpWebResponse.Headers["Set-Cookie"]) ? "" : httpWebResponse.Headers["Set-Cookie"];
                    return httpWebResponse.ResponseUri.ToString();
                }
            }
            catch (Exception er)
            {
                this.Invoke(new UpdateResultCallback(this.UpdateResult), new object[] { er.Message });
                return null;
            }
         }

Последний раз редактировалось WAYS; 14.03.2010 в 14:44..
 
Ответить с цитированием