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:
Y también intente usando:
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!
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 (csharp) [Seleccionar]
CookieContainer Cookies = new CookieContainer();
private void button1_Click(object sender, EventArgs e)
{
string url = "http://foro.elhacker.net/";
string vars = "user=usuario&passwrd=password";
string data_post = "subject=" + title.Text + "&message=" + message.Text;
if (login(url, vars, url))
{
publicar(url, data_post, 62);
}
else
{
MessageBox.Show("Ocurrio un Error");
}
}
public bool login(string url, string vars, string refer = "")
{
Encoding charset = Encoding.GetEncoding("iso-8859-1");
byte[] buffer = charset.GetBytes(vars);
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(url + "index.php?action=login2");
Request.Referer = refer;
Request.UserAgent = "Mozilla/5.0 (Windows; Windows NT 6.1) AppleWebKit/534.23 (KHTML, like Gecko) Chrome/11.0.686.3 Safari/534.23";
Request.Method = "POST";
Request.KeepAlive = true;
Request.CookieContainer = new CookieContainer();
Request.ContentType = "application/x-www-form-urlencoded";
Request.ContentLength = buffer.Length;
Request.AllowAutoRedirect = true;
Stream PostData = Request.GetRequestStream();
PostData.Write(buffer, 0, buffer.Length);
PostData.Close();
HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
foreach (Cookie cook in Response.Cookies)
{
Cookies.Add(cook);
}
Stream Answer = Response.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);
string respuesta = _Answer.ReadToEnd();
loginurl.Text = Response.ResponseUri.ToString();
Response.Close();
Answer.Close();
_Answer.Close();
if (!respuesta.Contains("id=\"button_login\"") && !respuesta.Contains("<input type=\"text\" name=\"user\"")) return true;
return false;
}
public void publicar(string url, string data_post, int id)
{
Encoding charset = Encoding.GetEncoding("iso-8859-1");
byte[] buffer = charset.GetBytes(data_post);
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(url + "index.php?action=post2;start=0;board=" + id);
Request.Referer = url;
Request.UserAgent = "Mozilla/5.0 (Windows; Windows NT 6.1) AppleWebKit/534.23 (KHTML, like Gecko) Chrome/11.0.686.3 Safari/534.23";
Request.Method = "POST";
Request.KeepAlive = true;
Request.CookieContainer = Cookies;
Request.ContentType = "application/x-www-form-urlencoded";
Request.ContentLength = buffer.Length;
Request.AllowAutoRedirect = true;
Stream PostData = Request.GetRequestStream();
PostData.Write(buffer, 0, buffer.Length);
PostData.Close();
HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
Stream Answer = Response.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer, Encoding.GetEncoding("iso-8859-1"));
post.Text = _Answer.ReadToEnd();
posturl.Text = Response.ResponseUri.ToString();
Response.Close();
Answer.Close();
_Answer.Close();
}
Y también intente usando:
Código (csharp) [Seleccionar]
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!
