K
Hi,
heute bin ich wieder dazugekommen etwas weiter zu entwickeln...
Einloggen und Seiten aufrufen klappt super blos will ich jetzt in einem Forum posten können und das tut irgendwie nicht.
Laut dem IE HTTP Analizer werden folgende Daten gesendet:
title=Re%3A+%5B.NET%5D+Problem+mit+Pointer+oder+so+%C3%A4hnlich&message=qwertz&wysiwyg=0&iconid=0&s=&securitytoken=1299541972-2ad858e638eda8c0c6fa5119f0e39f08249dac76&do=postreply&t=1641679&p=13778829&specifiedpost=0&posthash=ba36d4b59e715facf9272795c6c95185&poststarttime=1299541972&loggedinuser=344783&multiquoteempty=&sbutton=Antworten&signature=1&parseurl=1&emailupdate=2
Währe super wenn jemand die Zeit hätte sich folgenden Code nochmal anzuschauen.
Code:
private void button1_Click(object sender, EventArgs e)
{
string url = "http://board.gulli.com";
webBrowser1.DocumentText = sendRequest(url);
}
public string sendRequest(string url)
{
//LOGIN
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] loginData = encoding.GetBytes("do=login" + "&vb_login_username=" + id01.Text + "&vb_login_password=" + pw01.Text);
CookieContainer cookieContainer = new CookieContainer();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + "/login.php?do=login");
request.CookieContainer = cookieContainer;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
Stream stream = request.GetRequestStream();
stream.Write(loginData, 0, loginData.Length);
stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//GET PLAIN HTML
request = (HttpWebRequest)WebRequest.Create(url + "/newreply.php?do=newreply&noquote=1&p=13778773");
request.CookieContainer = cookieContainer;
request.Method = "GET";
response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
string sourceCode = sr.ReadToEnd();
response.Close();
// GET POST STRING
byte[] postData = encoding.GetBytes(formPostMsg(sourceCode));
// SEND POST STRING
request = (HttpWebRequest)WebRequest.Create(url + "/newreply.php?do=newreply&noquote=1&p=13778773");
request.CookieContainer = cookieContainer;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
stream = request.GetRequestStream();
stream.Write(postData, 0, postData.Length);
stream.Close();
response = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(response.GetResponseStream());
sourceCode = sr.ReadToEnd();
response.Close();
//RETURN FINAL HTML TO WEBCONTROL
return sourceCode;
}
public string formPostMsg(string sourceCode)
{
ArrayList postValue = new ArrayList();
postValue.Add("title="+"RERERERERERERE");
postValue.Add("message=" + "messagemessagemessagemessage");
postValue.Add("wysiwyg=" + "0");
postValue.Add("iconid=" + "0");
postValue.Add("s=" + "");
string startindex = "<input type=\"hidden\" name=\"securitytoken\" value=\"";
int startIndex = sourceCode.IndexOf(startindex) + startindex.Length;
int endIndex = sourceCode.IndexOf("\" />", startIndex);
postValue.Add("securitytoken=" + sourceCode.Substring(startIndex, endIndex - startIndex));
startindex = "<input type=\"hidden\" name=\"t\" value=\"";
startIndex = sourceCode.IndexOf(startindex) + startindex.Length;
endIndex = sourceCode.IndexOf("\" />", startIndex);
postValue.Add("t=" + sourceCode.Substring(startIndex, endIndex - startIndex));
startindex = "<input type=\"hidden\" name=\"p\" value=\"";
startIndex = sourceCode.IndexOf(startindex) + startindex.Length;
endIndex = sourceCode.IndexOf("\" />", startIndex);
postValue.Add("p=" + sourceCode.Substring(startIndex, endIndex - startIndex));
startindex = "<input type=\"hidden\" name=\"posthash\" value=\"";
startIndex = sourceCode.IndexOf(startindex) + startindex.Length;
endIndex = sourceCode.IndexOf("\" />", startIndex);
postValue.Add("specifiedpost=" + "");
postValue.Add("posthash=" + sourceCode.Substring(startIndex, endIndex - startIndex));
startindex = "<input type=\"hidden\" name=\"poststarttime\" value=\"";
startIndex = sourceCode.IndexOf(startindex) + startindex.Length;
endIndex = sourceCode.IndexOf("\" />", startIndex);
postValue.Add("poststarttime=" + sourceCode.Substring(startIndex, endIndex - startIndex));
startindex = "<input type=\"hidden\" name=\"loggedinuser\" value=\"";
startIndex = sourceCode.IndexOf(startindex) + startindex.Length;
endIndex = sourceCode.IndexOf("\" />", startIndex);
postValue.Add("loggedinuser=" + sourceCode.Substring(startIndex, endIndex - startIndex));
postValue.Add("multiquoteempty=" + "");
postValue.Add("sbutton=" + "Antworten");
postValue.Add("signature=" + "1");
postValue.Add("parseurl=" + "1");
postValue.Add("emailupdate=" + "2");
MessageBox.Show(string.Join("&", postValue.ToArray(typeof(string)) as string[]));
return string.Join("&", postValue.ToArray(typeof(string)) as string[]);
}