Click here to Skip to main content
14,773,484 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am trying to login into a website using HTTP-POST method in c#

but the response i get is the login page itself not the logged in page?
Also i need a persistent session so i think i need to be using cookies is that correct? if yes how?

here is the html source snippet to login

<form onsubmit="return !(!this.PASSWORD.value||!this.USERNAME.value);" action="/login.html" method="post" name="loginform">


What I have tried:

class Program
    {
        static void Main(string[] args)
        {
            string username = "####";
            string password = "########";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://ftrpoker.com/login.html");
            request.Method = "POST";
            using (StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.ASCII))
            {
                writer.Write("USERNAME=" + username + "&PASSWORD=" + password);
            }

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            //Retrieve your cookie that id's your session
            //response.Cookies

            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                Console.WriteLine(reader.ReadToEnd());
        }

    }   
Posted
Updated 29-Aug-17 1:00am
v2
Comments
Suvendu Shekhar Giri 29-Aug-17 3:17am
   
What exactly are you trying to do here?
Login automatically using console application?
gooplix 29-Aug-17 3:35am
   
I am trying to write a program to scrape hand history, for which i need to login first
Graeme_Grant 29-Aug-17 3:28am
   
You know logging in like a bot will most likely get you kicked from their servers if you do not have the approval to do so... If they had wanted to allow you to, they would have an API.
gooplix 29-Aug-17 3:37am
   
No api is provided, i will not get banned as i asked for API and they said you may write a bot to do this, so have permission
Graeme_Grant 29-Aug-17 3:39am
   
Then they are the best people to ask how to write a login...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900