Mam problem z zalegowaniem na forum csharp.pl. W jaki sposób sprawdzić czy użytkownik zalogował się czy też nie na forum? Mój kod wygląda następująco.
string textAnswer = null;
string dataToSend = "username=aaaa&password=password111";//"vb_login_username=userid11&vb_login_password=password111";
byte[] buffer = Encoding.ASCII.GetBytes(dataToSend);
Uri uri = new Uri("http://www.csharp.pl/ucp.php?mode=login");//"http://www.thinkdigit.com/forum/login.php");
HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(uri);
webRequest.Method = "POST";//WebRequestMethods.Http.Post;
webRequest.ContentLength = dataToSend.Length;
//We use form contentType, for the dataToSend
webRequest.ContentType = "application/x-www-form-urlencoded";
//The length of the buffer (dataToSend) is used as contentlength.
webRequest.ContentLength = buffer.Length;
//We open a stream for writing the dataToSend
Stream postData = webRequest.GetRequestStream();
//Now we write, and afterwards, we close. Closing is always important!
postData.Write(buffer, 0, buffer.Length);
postData.Close();
//Get the response handle, we have no true response yet!
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
richTextBox1.AppendText("webResponse.StatuseCode: " + webResponse.StatusCode);
richTextBox1.AppendText("\r\nwebResponse.Server: " + webResponse.Server);
//Now, we read the response (the string), and output it.
Stream answer = webResponse.GetResponseStream();
StreamReader srAnswer = new StreamReader(answer);
textAnswer = srAnswer.ReadToEnd();
richTextBox1.AppendText("Answer:\r\n" + textAnswer);