2013-06-10, 09:17 AM
I decided to take on a challenge. If I can get this code here downpat, I should be able to make the rest of it work.
I have a Windows Form, trying to log in to a MyBB powered forum with it. This is the processing code I have:
The long and short of it is, the file being written returns the contents of an un-logged-in webpage. Any clues what is going wrong? I've tried pointing the form to member.php?action=do_login, no dice. I know the username and password I am using are correct.
I have a Windows Form, trying to log in to a MyBB powered forum with it. This is the processing code I have:
public void login(string username, string password)
{
byte[] buffer = Encoding.ASCII.GetBytes("username=" + username + "&password=" + password + "&action=do_login");
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://example.com/member.php");
request.Method = "POST";
request.ContentLength = buffer.Length;
request.AllowAutoRedirect = true;
using (Stream reqStream = request.GetRequestStream())
{
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Close();
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (Stream respStream = response.GetResponseStream())
{
using (StreamReader sr = new StreamReader(respStream))
{
string s = sr.ReadToEnd();
string[] res = new string[]
{
s
};
File.WriteAllLines(@"C:\Users\*****\Desktop\response.txt", res);
}
}
}
The long and short of it is, the file being written returns the contents of an un-logged-in webpage. Any clues what is going wrong? I've tried pointing the form to member.php?action=do_login, no dice. I know the username and password I am using are correct.