elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Los 10 CVE más críticos (peligrosos) de 2020


  Mostrar Temas
Páginas: [1]
1  Programación / .NET (C#, VB.NET, ASP) / Problema al intentar publicar contenido con HttpWebRequest en: 2 Agosto 2013, 16:59 pm
Hola.

Bueno pues eso, estoy intentando usar HttpWebRequest para publicar por ejemplo en un foro (dejo ejemplo para este foro), cuando es solo para loguearse si funciona, pero ya para publicar no:

Código
  1. CookieContainer Cookies = new CookieContainer();
  2. private void button1_Click(object sender, EventArgs e)
  3.        {
  4.            string url = "http://foro.elhacker.net/";
  5.            string vars = "user=usuario&passwrd=password";
  6.            string data_post = "subject=" + title.Text + "&message=" + message.Text;
  7.            if (login(url, vars, url))
  8.            {
  9.                publicar(url, data_post, 62);
  10.            }
  11.            else
  12.            {
  13.                MessageBox.Show("Ocurrio un Error");
  14.            }
  15.        }
  16.  
  17.        public bool login(string url, string vars, string refer = "")
  18.        {
  19.            Encoding charset = Encoding.GetEncoding("iso-8859-1");
  20.            byte[] buffer = charset.GetBytes(vars);
  21.            HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(url + "index.php?action=login2");
  22.            Request.Referer = refer;
  23.            Request.UserAgent = "Mozilla/5.0 (Windows; Windows NT 6.1) AppleWebKit/534.23 (KHTML, like Gecko) Chrome/11.0.686.3 Safari/534.23";
  24.            Request.Method = "POST";
  25.            Request.KeepAlive = true;
  26.            Request.CookieContainer = new CookieContainer();
  27.            Request.ContentType = "application/x-www-form-urlencoded";
  28.            Request.ContentLength = buffer.Length;
  29.            Request.AllowAutoRedirect = true;
  30.  
  31.            Stream PostData = Request.GetRequestStream();
  32.            PostData.Write(buffer, 0, buffer.Length);
  33.            PostData.Close();
  34.  
  35.  
  36.            HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
  37.  
  38.            foreach (Cookie cook in Response.Cookies)
  39.            {
  40.                Cookies.Add(cook);
  41.            }
  42.            Stream Answer = Response.GetResponseStream();
  43.            StreamReader _Answer = new StreamReader(Answer);
  44.            string respuesta = _Answer.ReadToEnd();
  45.            loginurl.Text = Response.ResponseUri.ToString();
  46.            Response.Close();
  47.            Answer.Close();
  48.            _Answer.Close();
  49.            if (!respuesta.Contains("id=\"button_login\"") && !respuesta.Contains("<input type=\"text\" name=\"user\"")) return true;
  50.            return false;
  51.        }
  52.  
  53.        public void publicar(string url, string data_post, int id)
  54.        {
  55.  
  56.            Encoding charset = Encoding.GetEncoding("iso-8859-1");
  57.            byte[] buffer = charset.GetBytes(data_post);
  58.            HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(url + "index.php?action=post2;start=0;board=" + id);
  59.            Request.Referer = url;
  60.            Request.UserAgent = "Mozilla/5.0 (Windows; Windows NT 6.1) AppleWebKit/534.23 (KHTML, like Gecko) Chrome/11.0.686.3 Safari/534.23";
  61.            Request.Method = "POST";
  62.            Request.KeepAlive = true;
  63.            Request.CookieContainer = Cookies;
  64.            Request.ContentType = "application/x-www-form-urlencoded";
  65.            Request.ContentLength = buffer.Length;
  66.            Request.AllowAutoRedirect = true;
  67.  
  68.            Stream PostData = Request.GetRequestStream();
  69.            PostData.Write(buffer, 0, buffer.Length);
  70.            PostData.Close();
  71.  
  72.  
  73.            HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
  74.  
  75.            Stream Answer = Response.GetResponseStream();
  76.            StreamReader _Answer = new StreamReader(Answer, Encoding.GetEncoding("iso-8859-1"));
  77.            post.Text = _Answer.ReadToEnd();
  78.            posturl.Text = Response.ResponseUri.ToString();
  79.            Response.Close();
  80.            Answer.Close();
  81.            _Answer.Close();
  82.        }

Y también intente usando:

Código
  1. Request.Credentials = new NetworkCredential("usuario", "password");

Pero de ninguna forma me funciono   :-(

El problema es que me dice que no estoy logueado, ¿como le tendria que hacer para que se loguee y publique?

Saludos!   ;)
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines