3
Reply

How to log into a website with c#

Oliver Tatlow

Oliver Tatlow

Jul 26 2013 10:27 AM
3k
I'm wanting to return the html from a webpage which requires that I'm logged in.

This is the code I've got so far.

    private
void toolStripButton1_Click(object sender, EventArgs e)  
    {

        var request = WebRequest.Create("http://www.conquerclub.com/game.php?game=13025037");
       
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        StreamReader
reader = new StreamReader(response.GetResponseStream());
        richTextBox1
.Text = reader.ReadToEnd();
    }

As expected this automatically re-directs to the login page and returns that. How do I pass my username and login so that it will automatically log in and go to the right page?

login name - testuser1
password - testing
(I've created this account so it will actually log in with these credentials)

I've had a look around and found lots of different ways suggested to do this but can't get anything to work. Would be absolutely brilliant if someone could provide code that will make this happen.

Answers (3)