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[]);
}