I am trying to login to a website "https://my.freecycle.org/" I have tried various methods including this stackoverflow Login to website, via C# but with no luck, it does not appear to be a standard form.
<form method="post" class="cols_2" action="https://my.freecycle.org/login" id="loginform" accept-charset="utf-8"><fieldset>
<input type="hidden" name="referer" value="">
<label for="username">Username (or email address):</label>
<input type="text" name="username" id="username"><br>
<label for="pass">Password:</label>
<input type="password" name="pass" id="pass"><br>
<input type="submit" value="Log in" class="button defaultButton vgap ui-button ui-widget ui-state-default ui-corner-all" role="button" aria-disabled="false">
I would really appreciate some help with this, below is the code I tried.
private void button1_Click(object sender, EventArgs e)
{
CookieAwareWebClient client = new CookieAwareWebClient();
client.BaseAddress = @"https://my.freecycle.org/";
NameValueCollection loginData = new NameValueCollection();
loginData.Add("username", @"myemail@gmail.com");
loginData.Add("pass", "mypassword");
client.UploadValues("login", "POST", loginData);
//Now you are logged in and can request pages
string htmlSource = client.DownloadString(client.BaseAddress);
textBox1.Text = htmlSource;
}
public class CookieAwareWebClient : WebClient
{
private CookieContainer cookie = new CookieContainer();
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request = base.GetWebRequest(address);
if (request is HttpWebRequest)
{
(request as HttpWebRequest).CookieContainer = cookie;
}
return request;
}
}